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

ElHaix picture ElHaix · Nov 25, 2009 · Viewed 51.5k times · Source

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);.

Answer

bendewey picture bendewey · Apr 28, 2010

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();