Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WCF and Multiple Host Headers

Tags:

c#

iis

wcf

iis-6

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 :)

like image 787
Ryu Avatar asked Jan 07 '09 22:01

Ryu


2 Answers

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>
like image 52
thaBadDawg Avatar answered Oct 15 '22 05:10

thaBadDawg


I don't think that the host base addresses solution posted above will work for IIS-hosted websites (the OP did mention that this was for his employer's website).

See this blog post

Also, the other answer further up by thaBadDawg won't work where multiple host headers are specified - you'll just get the errors that the OP mentions ("This collection already contains an address with scheme http".)

I don't think any of the solutions mentioned so far will work, because it doesn't look like WCF allows a single service to be accessible for a single site with multiple host headers from all of the sites. The only workaround I could find for .Net 3.5 (and under) is to create a different contract for each of the host headers, and use the custom ServiceHostFactory to use the correct host header based on which contract is specified. This isn't at all practical. Apparently .Net 4.0 will resolve this issue.

like image 33
zcrar70 Avatar answered Oct 15 '22 07:10

zcrar70