WCF: Handling multiple IIS bindings - This collection already contains an address with scheme http

 

Environment: IIS configured for multiple bindings with different host headers.

 

 

WCF Reporting Error: This collection already contains an address with scheme http.

 

IIS supports specifying multiple IIS bindings per site, which results in multiple base addresses per scheme.

A WCF service hosted under a site allows binding to only one baseAddress per scheme.

 

Resolution (Depending on the framework used)

 

1.      Framework 3.0

Not supported - http://msdn.microsoft.com/en-us/library/aa751841(v=vs.85).aspx

  

2.      Framework 3.5

Using Base Address Prefix Filter - http://msdn.microsoft.com/en-us/library/bb924481.aspx

Step1.

      <baseAddressPrefixFilters>

        <add prefix="http://server1:81/"/>

      </baseAddressPrefixFilters>

You can refer your one of the host header URI here.

Step2.

        <endpoint   address="http://server1:81/Service1.svc/server1" binding="wsHttpBinding" contract="WcfService1.IService1" />

        <endpoint address="http://server2:81/Service1.svc/server2" binding="wsHttpBinding" contract="WcfService1.IService1"/>

 We need to add two end point, with respective Address (both pointing to different host headers)

  

3.       Framework 4.0

To enable support for multiple bindings in IIS we can set ServiceHostingEnvironment’s MultipleSiteBindingsEnabled to true. This support is limited to HTTP protocol schemes. 

http://msdn.microsoft.com/en-us/library/system.servicemodel.configuration.servicehostingenvironmentsection.multiplesitebindingsenabled.aspx

              <system.serviceModel>

  <serviceHostingEnvironment multipleSiteBindingsEnabled=”true” >

  </serviceHostingEnvironment>

</system.serviceModel>

 

Note: Any baseAddressPrefixFilters settings are ignored when this setting is set to TRUE.