gpt4 book ai didi

c# - jQuery 使用 JSON WCF

转载 作者:行者123 更新时间:2023-11-30 18:41:10 24 4
gpt4 key购买 nike

我有一个带有 3 个字符串参数的 WCF 服务。使用 jQuery 和 JSON 调用它确实到达了我的方法,但只有 1 个参数包含一个值 - 其他参数接收到 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 中的参数名称。愚蠢。

谢谢大家的回复。

关于c# - jQuery 使用 JSON WCF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7219695/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com