WCF Error on execute: Manual addressing is enabled on this factory, so all messages sent must be pre-addressed

Amintabar picture Amintabar · Jan 18, 2014 · Viewed 13.4k times · Source

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.

Server Side

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

Client Side

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>

Answer

Amintabar picture Amintabar · Jan 18, 2014

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>

The problem should be solved.