I have a WCF service with 3 string arguments. Calling this with jQuery and JSON does reach my method but only 1 of the arguments contain a value – the others are received null, even though they are passed. Any thoughts why?
[WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
public string Save(string site, string title, string contentType)
{
// method...
}
JS:
$.ajax(
{
type: "POST",
url: "/Service.svc/Save",
dataType: "json",
data: "{\"title\": \"title...\", \"site\": \"site...\", \"contentType\": \"contentType...\"}",
contentType: "application/json; charset=utf-8",
success: function(data) {
},
error: function() {
alert("Sorry, an error has occured");
}
}
False alarm.
The argument name for those two missing arguments was different in the ServiceContract to the service. I was using the argument name that was in the service, not the one in the ServiceContract. Stupid.
Thanks for the replies guys.