WCF and Multiple Host Headers

Ryu picture Ryu · Jan 7, 2009 · Viewed 8.6k times · Source

My employers website has multiple hostnames that all hit the same server and we just show different skins for branding purposes.

Unfortunately WCF doesn't seem to work well in this situation.

I've tried overriding the default host with a custom host factory.

That's not an acceptable solution because it needs to work from all hosts, not just 1.

I've also looked at this blog post but either I couldn't get it to work or it wasn't meant to solve my problem.

The error I'm getting is "This collection already contains an address with scheme http"

There's got to be a way to configure this, please help :)

Answer

thaBadDawg picture thaBadDawg · Jan 7, 2009

If you don't put an address in the endpoint then it should resolve to whatever server hits the service. I use this code and it resolves both to my .local address and to my .com address from IIS.

<system.serviceModel>
    <services>
        <service name="ServiceName" behaviorConfiguration="ServiceName.Service1Behavior">
            <endpoint address="" binding="wsHttpBinding" contract="iServiceName">
            </endpoint>
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
        </service>
    </services>
    <behaviors>
        <serviceBehaviors>
            <behavior name="ServiceName.Service1Behavior">
                <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
                <serviceMetadata httpGetEnabled="true"/>
                <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
                <serviceDebug includeExceptionDetailInFaults="true"/>
            </behavior>
        </serviceBehaviors>
    </behaviors>
</system.serviceModel>