部署 wcf 服务 (.net 4.0)。服务端配置如下:
<endpoint address=""
binding="webHttpBinding"
bindingNamespace="https://mydomain/myservice/services"
behaviorConfiguration="WebBehavior"
contract="MyService" />
<endpointBehaviors>
<behavior name="WebBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
尝试在 Web 应用程序中使用服务,
web.config
好像:<system.serviceModel>
<client>
<endpoint name="MyServiceEndpointBasicHttp"
address="http://myDomain/myService"
binding="webHttpBinding" behaviorConfiguration="webBehavior"
contract="MyNamespace.IMyService" />
</client>
<behaviors>
<endpointBehaviors>
<behavior name="webBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
调用服务时出现异常:
Operation 'Method1' of contract 'IMyService' specifies multiple request body parameters to be serialized without any wrapper elements. At most one body parameter can be serialized without wrapper elements. Either remove the extra body parameters or set the BodyStyle property on the WebGetAttribute/WebInvokeAttribute to Wrapped.
经过一些谷歌搜索,我们设置了
[WebGet(BodyStyle = WebMessageBodyStyle.WrappedRequest, ResponseFormat = WebMessageFormat.Xml)]
在方法上,但没有成功......一件有趣的事情:异常中总是有相同的方法名称,即使我正在调用其他方法......
服务在 REST 模式下工作正常,同时通过输入方法名称和必要的参数使用浏览器进行测试...
最佳答案
您似乎面临与此线程类似的问题:WCF Service Proxy throws exception when more than one parameter is used in [OperationContract] method
“您似乎已经使用 VS 中的“添加服务引用”对话框创建了代理代码。VS ASR 对话框不完全支持 WCF REST,因此,代理代码缺少 [WebInvoke] 属性。您可以尝试添加 [WebInvoke(BodyStyle = WebMessageBodyStyle. Wrapped)] 属性在客户端代理中的操作?”
关于.net - 如何在 REST 模式下使用 WCF 服务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4540042/