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 onl开发者_开发技巧y 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();
}
According to my knowledge, ado.net data service has some limitation toward your approach, one alternatively, you could pass your parameters using get request, if you are sending huge parameter u could use $batch to overcome that.
http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataservices/thread/40a1d8a2-c0d7-45ff-88a0-ce8697b37155
精彩评论