[英]jQuery consuming JSON WCF
我有一个带有3个字符串参数的WCF服务。 使用jQuery和JSON调用它确实达到了我的方法,但只有一个参数包含一个值 - 其他的都被接收为null,即使它们被传递。 有什么想法?
[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");
}
}
误报。
这两个缺少的参数的参数名称在服务的ServiceContract中是不同的。 我使用的是服务中的参数名称,而不是ServiceContract中的参数名称。 笨。
谢谢回复人员。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.