Thursday, June 18, 2009

WCF on Multi Host Servers

I ran into this problem today when I was working on a WCF project.  A project which was working fine on my machine start producing the error “This collection already contains an address with scheme http.  There can be at most one address per scheme in this collection. Parameter name: item

image

Turns out that because the server was hosting a number of different sites using different Host Headers WCF needs to know which of the hosts to respond too.  You can do this by added the following to the services web.config file.

  <system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true">
    <baseAddressPrefixFilters>
        <add prefix="http://www.blahblah.com"/>
    </baseAddressPrefixFilters>
    </serviceHostingEnvironment>

        ……

   </system.serviceModel>

 

That tells the service to only respond on the specific header.