WCF使用参数发出POST请求

时间:2012-03-28 11:52:22

标签: json wcf post fiddler

我有一个暴露休息端点的wcf服务。我想用fiddler来测试它。我有这样的方法:

 [WebInvoke(Method = "POST", UriTemplate = "EditContact", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)]
    string EditContact(string idContact, Contact Contact);

我输入:

  

POST http://192.168.1.31/ContactLibrary2.0/Service.svc/rest/DeleteContact HTTP / 1.1

User-Agent: Fiddler
Host: 192.168.1.31
Content-Type : application/json; Charset=UTF-8

{
"idContact":"67697",
"firstName":"6767",
"lastName":"afdgsg",
"email":"dfghdfdb",
"age":"120",
"street":"sdf",
"city":"dfghgfhjhdfgsdv",
"country":"sdfsd"
}

您可以看到我的项目中的更多代码:HERE

我收到http 400错误(错误的请求错误)。想法?

1 个答案:

答案 0 :(得分:8)

您的请求应如下所示:

POST  http://192.168.1.31/ContactLibrary2.0/Service.svc/rest/DeleteContact HTTP/1.1
User-Agent: Fiddler
Content-Type: application/json

{
    "idContact":5,
    "Contact":{
        "idContact":"67697",
        "firstName":"6767",
        "lastName":"afdgsg",
        "email":"dfghdfdb",
        "age":"120",
        "street":"sdf",
        "city":"dfghgfhjhdfgsdv",
        "country":"sdfsd"
    }
}