Doing a POST to a Service Operation in ADO.NET data services
- by DataServices123
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();
}