我正在尝试使用svcutil生成的客户端与RESTful WCF服务进行通信。
服务合同定义为:
public interface IService1
{
[OperationContract]
[WebGet(UriTemplate = "/GetTest?a={a}&b={b}&c={c}")]
int GetTest(int a, int b, int c);
}我使用Visual Studio来引用此服务,并使用生成的客户端代码来调用GetTest操作。不幸的是,我收到了这样的消息:
Operation 'GetTest' of contract 'IService1' specifies multiple request body parameters to be serialized without any wrapper elements. At most one body parameter can be serialized without wrapperelements. Either remove the extra body parameters or set the BodyStyle property on the WebGetAttribute/WebInvokeAttribute to Wrapped但是当我从web浏览器请求相应的URL时,它工作了,并显示了正确的返回值。
这很奇怪。生成的客户端代码有什么问题吗?还是我配置错了什么?
以下是我的客户端配置:
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="Service1EndPointBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<client>
<endpoint address="http://localhost:8010/Service1/" behaviorConfiguration="Service1EndPointBehavior"
binding="webHttpBinding" contract="ServiceReference1.IService1"
name="Service1EndPoint" />
</client>
</system.serviceModel>谢谢。
发布于 2012-10-11 20:33:39
[WebInvoke(BodyStyle = WebMessageBodyStyle.Wrapped)]解释:
http://msdn.microsoft.com/en-us/library/system.servicemodel.web.webmessagebodystyle.aspx
https://stackoverflow.com/questions/12832429
复制相似问题