WCF 执行时出错:此工厂启用了手动寻址,因此所有发送的消息都必须预先寻址 [英] WCF Error on execute: Manual addressing is enabled on this factory, so all messages sent must be pre-addressed

查看:26
本文介绍了WCF 执行时出错:此工厂启用了手动寻址,因此所有发送的消息都必须预先寻址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由 WebHttpBinding 托管的 WCF 服务.服务很简单,一个接受多个参数的操作合约.我的 WCF 客户端在使用添加服务引用"后自动生成,无法直接使用 WCF 服务.错误只发生在 WebHttpBinding 上,其他的不发生.

I have a WCF service hosted with WebHttpBinding. The service is very simple, an operation contract which accept multiple parameters. My WCF client, auto generated after using the "Add Service Reference", is not able to directly consume the WCF service. The error only occur for WebHttpBinding but not the others.

服务端

[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");

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

When I test run my above code, I get the following error:

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

这是使用添加服务引用"后我自动生成的配置文件的样子:

Here is how my auto generated configuration file look like after using the "Add Service Reference":

 <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 有这个问题.要解决这个问题,只需在客户端配置文件中添加一个行为配置如下:

I realize that only WebHttpBinding has this problem. To solve this problem, just add a behavior configuration in the client side configuration file like this:

<behaviors>
    <endpointBehaviors>
        <behavior name="webEndpoint">
            <webHttp defaultBodyStyle="Wrapped" 
                     defaultOutgoingResponseFormat="Xml" 
                     helpEnabled="true"/>
        </behavior>
    </endpointBehaviors>
</behaviors>

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

Then, update the client endpoint to use the above endpoint behavior.

<client>
    <endpoint binding="webHttpBinding" 
              bindingConfiguration="webHttp" 
              behaviorConfiguration="webEndpoint"  
              contract="ExpenseService.IExpenseService" 
              address="http://myservices/ExpenseService.svc">
    </endpoint>
</client>

问题应该得到解决.

这篇关于WCF 执行时出错:此工厂启用了手动寻址,因此所有发送的消息都必须预先寻址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆