ASP.NET - WCF service method not called by API with Json string

Asked By asif hameed on 19-Apr-13 09:46 AM
Hi all:

I have created a web service using [WCF REST Service Template 40(CS)][1] like this:

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
public class RecordingCompleted

[WebInvoke(UriTemplate = "", Method = "POST", ResponseFormat = WebMessageFormat.Json,
RequestFormat = WebMessageFormat.Json)]
public string ProcessCall(string JsonData)

bool result = false;
JSONRecordingCompletedNotification RecordingCompletedNotification = new JavaScriptSerializer().Deserialize<JSONRecordingCompletedNotification>(JsonData);
string ConversationId = RecordingCompletedNotification.Content.ConversationId;

using (ICallRecordingManager CallRecordingManager = new ManagerFactory().GetCallRecordingManager())
CallRecording callRecording = CallRecordingManager.GetAll().Where(c => c.CallTrunkID == ConversationId).FirstOrDefault();

if (callRecording != null)
result = ProcessCallRecording(callRecording.Id);

return ConversationId;
catch (Exception ex)

string message = "error = " + ex.Message;

I have created a test app and trying to consume this service like:

string serviceBaseUrl = ConfigurationManager.AppSettings["serviceurl"].ToString(); 
string conversationId = ConfigurationManager.AppSettings["conversationId"].ToString();
string resourceUrl = "";
string method = "POST"; 
string jsonText = "{MyJsondatahere}";

string success = UseHttpWebApproach(serviceBaseUrl, resourceUrl, method, jsonText);

UseHttpWebApproach makes HttpWebRequest and gets response like this:

var response = request.GetResponse() as HttpWebResponse;

It all works great.

I am using a third party API which need a url to which it can send Json. I have given path of my WCF service like this:

but functionality inside this service method is not performed. API support team says that they have used a utilti nc.exe and see that difference is that API sends json without double quotes "" around it but my test app sends it as string. They get bad request when they use nc.exe. So Service works only if json is sent without double quotes. Is it possible to send JSON without double quotes.

Is there any other problem why even first line of the service is not called which simply adds an entry in txt log file ? Means I need to make the serviec method as WebGet instead of WebInvoke ? The service function just gets json and updates some tables.

I tried to save json in a txt file and then load it in string and send to service and it works because it is a string and enclosed by double quotes before and after {} like this:

"{\"Event\": ..... \"}";

Do I need to use Jquery AJAX for this ?

Please suggest.