2012-03-28 122 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