Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.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
如何使用WCF在UriTemplate中传递JSON字符串而不使用查询字符串_Wcf_C# 4.0_Wcf Rest - Fatal编程技术网

如何使用WCF在UriTemplate中传递JSON字符串而不使用查询字符串

如何使用WCF在UriTemplate中传递JSON字符串而不使用查询字符串,wcf,c#-4.0,wcf-rest,Wcf,C# 4.0,Wcf Rest,我能够通过查询字符串传递json字符串。但是,当我想传递pass而不传递查询字符串时,我得到了错误 http://localhost:51238/RestService.svc/FOSLoadingS1Opening?Data=[ { "Name":"Sachin", "City":"Bengalueu", "FimStatus":"false", "Deno1":"50", "Deno2":"100", "Deno3":"500", "Deno4":"2000", "IndtV

我能够通过查询字符串传递json字符串。但是,当我想传递pass而不传递查询字符串时,我得到了错误

http://localhost:51238/RestService.svc/FOSLoadingS1Opening?Data=[
{ 
"Name":"Sachin", 
"City":"Bengalueu", 
"FimStatus":"false", 
"Deno1":"50", 
"Deno2":"100", 
"Deno3":"500", 
"Deno4":"2000", 
"IndtVal1":"2500", 
"IndtVal2":"5000"  }]
当我传递上述URL时,我收到错误“错误请求”


我想在不使用查询字符串的情况下传递json字符串。请建议如何实现。

您必须将
WebInvoke
与方法POST结合使用

http://localhost:51238/RestService.svc/FOSLoadingS1Opening/[
{ 
"Name":"Sachin", 
"City":"Bengalueu", 
"FimStatus":"false", 
"Deno1":"50", 
"Deno2":"100", 
"Deno3":"500", 
"Deno4":"2000", 
"IndtVal1":"2500", 
"IndtVal2":"5000"  }]
现在,从客户端构造对象,并通过ajax调用发送json字符串化数据

[OperationContract]
[WebInvoke(Method = "POST",
            RequestFormat = WebMessageFormat.Json,
            ResponseFormat = WebMessageFormat.Json,
            UriTemplate = "SaveData/{id}")]
string SaveData(YourType typeObj);

唯一的方法是使用webinvoke(post)而不是webget
    var obj = {
        "Name":"Sachin", 
        "City":"Bengalueu", 
        "FimStatus":"false", 
        ...
    };
    $.ajax({
        type: "POST",
        url: "http://localhost/wcf.svc/SaveData/0",
        data: JSON.stringify(obj),
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        processData: true,
        success: function (data, status, jqXHR) {
            alert("success..." + data);
        },
        error: function (xhr) {
            alert(xhr.responseText);
        }
    });