Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I've got a hosted WCF service that I created a custom factory for, so that this would work with multiple host headers:

/// <summary>
/// Required for hosting where multiple host headers are present
/// </summary>
public class MultipleHostServiceFactory : ServiceHostFactory
{
    protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
    {
        List<Uri> addresses = new List<Uri>();
        addresses.Add(baseAddresses[0]);
        return base.CreateServiceHost(serviceType, addresses.ToArray());
    }
}

I'm pretty sure that my config files are now right, on both client and server (can be seen here).

The error I'm getting appears to be related to the factory:

Manual addressing is enabled on this factory, so all messages sent must be pre-addressed.

public string GetData(int value) {
    return base.Channel.GetData(value);
}

The error occurs at line return base.Channel.GetData(value);.

like image 778
ElHaix Avatar asked Nov 25 '09 16:11

ElHaix


3 Answers

I experienced this error and the problem was resolved by adding the WebHttpBehavior (line 2 below):

var factory = new ChannelFactory<IService>(new WebHttpBinding(), uri);
factory.Endpoint.Behaviors.Add(new WebHttpBehavior());
var proxy = factory.CreateChannel();
like image 179
bendewey Avatar answered Nov 11 '22 04:11

bendewey


I added a service reference as usual and got this error. Turns out all I had to do was to amend the client config to use an endpoint config with a behaviour specifing webhttp

<client>
  <endpoint address="http://localhost:9000/GeoConverterService/GeoConverterService.svc"
            binding="webHttpBinding" 
            contract="GeoConverter.IGeoConverterService" 
            behaviorConfiguration="webhttp"/>
</client>

<behaviors>
  <endpointBehaviors>
    <behavior name="webhttp">
      <webHttp/>
    </behavior>
  </endpointBehaviors>
</behaviors>

like image 41
jason mardell Avatar answered Nov 11 '22 05:11

jason mardell


I don't think this necessarily has anything to do with your factory.

See

http://msdn.microsoft.com/en-us/library/system.servicemodel.channels.transportbindingelement.manualaddressing.aspx

or others among the first few Bing hits for "manualaddressing". It sounds like the binding being used is incompatible with some other portion of the stack/messaging logic.

like image 2
Brian Avatar answered Nov 11 '22 03:11

Brian