Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# jQuery使用JSON WCF_C#_Jquery_Wcf_Json - Fatal编程技术网

C# jQuery使用JSON WCF

C# jQuery使用JSON WCF,c#,jquery,wcf,json,C#,Jquery,Wcf,Json,我有一个带有3个字符串参数的WCF服务。用jQuery和JSON调用这个函数确实到达了我的方法,但只有一个参数包含值——其他参数接收为null,即使它们被传递。你知道为什么吗 [WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)] pu

我有一个带有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:

虚惊一场

这两个缺少的参数的参数名称在服务的ServiceContract中不同。我使用的是服务中的参数名称,而不是ServiceContract中的名称。愚蠢的


感谢各位的回复。

您是否尝试过更正参数顺序?您的服务方法接受订单站点、标题和内容类型中的参数,但您在订单标题、站点和内容类型中发送它。不确定这是否能解决问题,但值得一试。是的,对不起,我应该提到这一点。参数的顺序不会改变结果。Title是唯一一个收到其值的参数。当我尝试它时,它起作用。我在VS2010中创建了一个WCF服务应用程序,我的JQuery版本是1.5.1。这里有一个预感:重命名站点和contentType名称。您是否在客户端对参数进行编码?
                    $.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");
                        }
                      }