Doing a POST to a Service Operation in ADO.NET data services

Posted by DataServices123 on Stack Overflow See other posts from Stack Overflow or by DataServices123
Published on 2010-04-15T19:42:38Z Indexed on 2010/05/14 2:54 UTC
Read the original article Hit count: 217

Filed under:
|
|
|
|

Is it possible to POST to a service operation defined in an ADO.NET data service (it is decorated with WebInvoke)? I had no problem calling the service operation as an HTTP GET. However, when I switched to doing a POST, the stack trace consistently comes back with "Parameter cannot be NULL". I am using the jQuery syntax below, and sending the POST as JSON (though I'm not including the $.ajax call, the parameter names line up exactly). It would be possible to try this with WCF, as opposed to ADO.NET data services (newly renamed as WCF data services). However, my preference would be to use this approach first. I have tried this with and without the stringify method. Most examples online only show how to use a POST to entities (i.e. for handling CRUD operations). However, in this case we are POSTing to a Service Operation.

function PostToDataService() {
   varType = "POST";
   varUrl = "http://dev-server/MyServices/MyService.svc/SampleSO";
   varData = { CustomMessage: $("#TextBox1").val() };
   varData = JSON.stringify(varData);
   varContentType = "application/json; charset=utf-8";
   varDataType = "json";
   varProcessData = true;
   CallService();
}

© Stack Overflow or respective owner

Related posts about wcf

Related posts about jQuery