2012-03-28 115 views
2

我有一个公开休息端点的wcf服务。我想用小提琴来测试它。我有这样的方法:WCF使用参数进行POST请求

[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错误(错误的请求错误)。想法?

回答

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" 
    } 
} 
+0

非常感谢你。你为我节省了很多麻烦。 – 2012-03-29 09:52:45