【发布时间】:2011-05-31 05:10:22
【问题描述】:
已部署 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>
调用服务时出现异常:
合约操作'Method1' 'IMyService' 指定多个 请求正文参数为 没有任何包装的序列化 元素。最多一个身体参数 可以在没有包装器的情况下进行序列化 元素。要么删除多余的身体 参数或设置 BodyStyle 财产在 WebGetAttribute/WebInvokeAttribute 到 包裹起来。
经过一番谷歌搜索,我们在方法上设置了[WebGet(BodyStyle = WebMessageBodyStyle.WrappedRequest, ResponseFormat = WebMessageFormat.Xml)],但没有成功...
一个有趣的事情:异常中总是有相同的方法名称,即使我正在调用其他方法......
服务在 REST 模式下工作正常,同时通过输入方法名称和必要参数使用浏览器进行测试...
【问题讨论】:
-
您能否向我们展示服务合同以及您的服务方法的定义?