如何构建WCF http post调用的请求?
问题描述:
我有一个非常简单的服务,我摆弄定义为:如何构建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>
,我觉得我失去了一些东西相当明显。任何指针?
答
通过添加XmlSerializerFormatAttribute的方法导致此为预期
[OperationContract]
[XmlSerializerFormat]
[WebInvoke(UriTemplate = "Review/{val}", RequestFormat = WebMessageFormat.Xml, Method = "POST", BodyStyle=WebMessageBodyStyle.Bare)]
void SubmitReview(string val, UserReview review);
我的猜测是,DataContractSerializer的需要一些命名空间GOOP才能够知道如何反序列化对象开始工作。也许XMLSerializer更宽容。如果打开WCF跟踪并使用SvcTrace查看日志,您将会更好地了解发生了什么问题。事实上,如果你打算做任何WCF工作,我都会学会熟悉这个工具。 – 2010-05-05 12:34:39