c# – WCF执行错误:此工厂启用了手动寻址,因此必须预先发送所有发送的消息

c# – WCF执行错误:此工厂启用了手动寻址,因此必须预先发送所有发送的消息,第1张

概述我有一个使用WebHttpBinding托管的WCF服务.服务非常简单,是一个接受多个参数的 *** 作合同.使用“添加服务引用”后自动生成的我的WCF客户端无法直接使用WCF服务.该错误仅发生在WebHttpBinding而不是其他错误. 服务器端 [OperationContract][WebInvoke(Method = "POST", UriTemplate = "Submit2String", 我有一个使用WebhttpBinding托管的WCF服务.服务非常简单,是一个接受多个参数的 *** 作合同.使用“添加服务引用”后自动生成的我的WCF客户端无法直接使用WCF服务.该错误仅发生在WebhttpBinding而不是其他错误.

服务器端

[OperationContract][WebInvoke(Method = "POST",UriTemplate = "submit2String",RequestFormat = Webmessageformat.Xml,ResponseFormat = Webmessageformat.Xml,BodyStyle = WebMessageBodyStyle.Wrapped)]string submit2String(string input1,string input2);

客户端

ExpenseServiceClIEnt proxy = new ExpenseServiceClIEnt();proxy.submit2String("test1","test2");

当我测试运行上面的代码时,我收到以下错误:

Error: InvalIDOperationException was unhandled by user codeManual addressing is enabled on this factory,so all messages sent must be pre-addressed.

以下是使用“添加服务引用”后自动生成的配置文件的外观:

<system.serviceModel>  <bindings>    <webhttpBinding>      <binding name="webhttp">        <security mode="None">          <transport clIEntCredentialType="None" />        </security>      </binding>    </webhttpBinding>  </bindings>  <clIEnt>    <endpoint binding="webhttpBinding"               bindingConfiguration="webhttp"              contract="ExpenseService.IExpenseService"                address="http://localhost/myservices/ExpenseService.svc">    </endpoint>  </clIEnt></system.serviceModel>
解决方法 我意识到只有WebhttpBinding有这个问题.要解决此问题,只需在客户端配置文件中添加行为配置,如下所示:

<behaviors>    <endpointBehaviors>        <behavior name="webEndpoint">            <webhttp defaultbodyStyle="Wrapped"                      defaultOutgoingResponseFormat="Xml"                      helpEnabled="true"/>        </behavior>    </endpointBehaviors></behaviors>

然后,更新客户端端点以使用上述端点行为.

<clIEnt>    <endpoint binding="webhttpBinding"               bindingConfiguration="webhttp"               behaviorConfiguration="webEndpoint"                contract="ExpenseService.IExpenseService"               address="http://myservices/ExpenseService.svc">    </endpoint></clIEnt>

问题应该解决.

总结

以上是内存溢出为你收集整理的c# – WCF执行错误:此工厂启用了手动寻址,因此必须预先发送所有发送的消息全部内容,希望文章能够帮你解决c# – WCF执行错误:此工厂启用了手动寻址,因此必须预先发送所有发送的消息所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1218739.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-05
下一篇 2022-06-05

发表评论

登录后才能评论

评论列表(0条)

保存