C# 执行时WCF错误:此工厂已启用手动寻址,因此发送的所有邮件都必须预寻址

C# 执行时WCF错误:此工厂已启用手动寻址,因此发送的所有邮件都必须预寻址,c#,wcf,webhttpbinding,C#,Wcf,Webhttpbinding,我有一个用WebHttpBinding托管的WCF服务。服务非常简单,是一个接受多个参数的操作契约。我的WCF客户端在使用“添加服务引用”后自动生成,无法直接使用WCF服务。此错误仅在WebHttpBinding中发生,其他错误不发生 服务器端 [OperationContract] [WebInvoke(Method = "POST", UriTemplate = "Submit2String", RequestFormat = WebMessageFormat.Xml, ResponseFo

我有一个用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 code
Manual addressing is enabled on this factory, so all messages sent must be pre-addressed.
以下是使用“添加服务引用”后自动生成的配置文件的外观:


我意识到只有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>

问题应该解决。

配置应该是什么样子?
<client>
    <endpoint binding="webHttpBinding" 
              bindingConfiguration="webHttp" 
              behaviorConfiguration="webEndpoint"  
              contract="ExpenseService.IExpenseService" 
              address="http://myservices/ExpenseService.svc">
    </endpoint>
</client>