2010-05-05 145 views
0

我有一個非常簡單的服務,我擺弄定義爲:如何構建WCF http post調用的請求?

[OperationContract] 
[WebInvoke(UriTemplate = "Review/{val}", RequestFormat = WebMessageFormat.Xml, Method = "POST", BodyStyle=WebMessageBodyStyle.Bare)] 
void SubmitReview(string val, UserReview review); 

UserReview是,此刻,沒有屬性的類。所有非常基本的。當我嘗試在Fiddler中測試這個時,我得到一個錯誤的請求狀態(400)消息。

我試圖用細節來調用服務:

POST http://127.0.0.1:85/Service.svc/Review/hello 

頁眉

User-Agent: Fiddler 
Content-Type: application/xml 
Host: 127.0.0.1:85 
Content-Length: 25 

身體

<UserReview></UserReview> 

,我覺得我失去了一些東西相當明顯。任何指針?

回答

0

通過添加XmlSerializerFormatAttribute的方法導致此爲預期

[OperationContract] 
[XmlSerializerFormat] 
[WebInvoke(UriTemplate = "Review/{val}", RequestFormat = WebMessageFormat.Xml, Method = "POST", BodyStyle=WebMessageBodyStyle.Bare)] 
void SubmitReview(string val, UserReview review); 
+2

我的猜測是,DataContractSerializer的需要一些命名空間GOOP才能夠知道如何反序列化對象開始工作。也許XMLSerializer更寬容。如果打開WCF跟蹤並使用SvcTrace查看日誌,您將會更好地瞭解發生了什麼問題。事實上,如果你打算做任何WCF工作,我都會學會熟悉這個工具。 – 2010-05-05 12:34:39