Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/294.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# 将json参数传递给wcf rest服务post方法_C#_Ajax_Json_Wcf_Rest - Fatal编程技术网

C# 将json参数传递给wcf rest服务post方法

C# 将json参数传递给wcf rest服务post方法,c#,ajax,json,wcf,rest,C#,Ajax,Json,Wcf,Rest,我对WCF世界完全陌生。 我正在尝试对WCF服务方法进行POST调用,并将json数据传递给它。 我的代码片段如下所示: Ajax POST调用: function PostJSON() { var form_data = { "req_limitmsg_header": { "brch_code": "784", "rqst_id": "00129538",

我对WCF世界完全陌生。 我正在尝试对WCF服务方法进行POST调用,并将json数据传递给它。
我的代码片段如下所示:

Ajax POST调用:

function PostJSON() {

        var form_data = {
           "req_limitmsg_header": {
                "brch_code": "784",
                "rqst_id": "00129538",
                "tnx_id": "20150200008695",
                "inp_user_id": "UAT01",
                "inp_dttm": "20150311183413",
                "Func_code": "6010 ",
                "idms_tnx_type_code": "N",
                "Spaces": "12",
                "prod_ref_id": "12"
            } ,
            "req_limitmsg_detail": [
                {
                   "jrn_exc_cur_code": "0000",
                    "jrn_exc_act_no": "019000090000",
                    "sign of exc_acpt_amt": "+",
                    "exc_acpt_amt": "0000000000000000",
                    "sign of jrn_exc_amt": "+",
                    "jrn_exc_amt": "0000000001500000"
                },
                {
                    "jrn_exc_cur_code": "0000",
                    "jrn_exc_act_no": "019000090000",
                    "sign of exc_acpt_amt": "+",
                    "exc_acpt_amt": "0000000000000000",
                    "sign of jrn_exc_amt": "+",
                    "jrn_exc_amt": "0000000001500000"
                }
            ]
        };

        $.ajax({
            cache: 'false',
            async: 'false',
            type: 'POST',
            url: "http://localhost:10647/JsonTest.svc/Rest/RequestLimitCheckService",
            data: JSON.stringify(form_data),
            contentType: "application/json; charset=utf-8",
            dataType: 'json',
            crossDomain: true,
            processData: true,
            success: function (data, status, jqXHR) {
                if(data != null)
                {
                    alert("NOT NULL");
                    alert(data.toString());
                }
                else
                {
                    alert("NULL");
                    alert(data.toString());
                    alert(status.toString());
                }
            },
            error: function (response) {
                alert(response);
            }
        });
    }
 [WebInvoke(Method = "POST",  ResponseFormat = WebMessageFormat.Json,RequestFormat=WebMessageFormat.Json,BodyStyle = WebMessageBodyStyle.Wrapped,
            UriTemplate = "RequestLimitCheckService")]
        public string RequestLimitCheck(string form_data)
        {
//do somethig
}
WCF方法:

function PostJSON() {

        var form_data = {
           "req_limitmsg_header": {
                "brch_code": "784",
                "rqst_id": "00129538",
                "tnx_id": "20150200008695",
                "inp_user_id": "UAT01",
                "inp_dttm": "20150311183413",
                "Func_code": "6010 ",
                "idms_tnx_type_code": "N",
                "Spaces": "12",
                "prod_ref_id": "12"
            } ,
            "req_limitmsg_detail": [
                {
                   "jrn_exc_cur_code": "0000",
                    "jrn_exc_act_no": "019000090000",
                    "sign of exc_acpt_amt": "+",
                    "exc_acpt_amt": "0000000000000000",
                    "sign of jrn_exc_amt": "+",
                    "jrn_exc_amt": "0000000001500000"
                },
                {
                    "jrn_exc_cur_code": "0000",
                    "jrn_exc_act_no": "019000090000",
                    "sign of exc_acpt_amt": "+",
                    "exc_acpt_amt": "0000000000000000",
                    "sign of jrn_exc_amt": "+",
                    "jrn_exc_amt": "0000000001500000"
                }
            ]
        };

        $.ajax({
            cache: 'false',
            async: 'false',
            type: 'POST',
            url: "http://localhost:10647/JsonTest.svc/Rest/RequestLimitCheckService",
            data: JSON.stringify(form_data),
            contentType: "application/json; charset=utf-8",
            dataType: 'json',
            crossDomain: true,
            processData: true,
            success: function (data, status, jqXHR) {
                if(data != null)
                {
                    alert("NOT NULL");
                    alert(data.toString());
                }
                else
                {
                    alert("NULL");
                    alert(data.toString());
                    alert(status.toString());
                }
            },
            error: function (response) {
                alert(response);
            }
        });
    }
 [WebInvoke(Method = "POST",  ResponseFormat = WebMessageFormat.Json,RequestFormat=WebMessageFormat.Json,BodyStyle = WebMessageBodyStyle.Wrapped,
            UriTemplate = "RequestLimitCheckService")]
        public string RequestLimitCheck(string form_data)
        {
//do somethig
}
WCF接口

  [OperationContract]
  string RequestLimitCheck(string form_data);
发生的事情是我总是得到空字符串。我也尝试过指定查询字符串参数样式,但没有用。只有指定类来接受json数据,它才能正常工作。
如果我做错了什么或遗漏了什么,请告诉我

删除JSON.stringify(form_数据),改用form_数据,然后重试。此外,您还需要指定所需的请求格式类型。

@Sandeep我尝试删除JSON.stringify(form_数据)并仅使用form_数据,但它甚至没有命中WCF方法。另外,我在WCF方法中提到了请求格式的类型(请参阅上面的代码片段)尽管如此,使用上面的参考资料作为示例代码仍然不起作用,因为示例代码试图实现与您类似的功能。希望这会有所帮助。