Knowledgebase
WCF web service results in an error This collection already contains an address with scheme http
Posted by zz-James Moir on 22 June 2016 09:38 AM

Issue

When attempting to run a .NET web service based on WCF in .NET 3.5 you receive an error such as:

This collection already contains an address with scheme http.
There can be at most one address per scheme in this collection.

Reason

In a shared hosting environment IIS is configured to answer for multiple hostnames. This is typically the problem that causes the error above since IIS has more than one http binding configured to answer requests for a given web site.

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 and since IIS doesn't know which one is the correct name to answer the WCF service throws an exception.

Solution

Specifying a <baseAddressPrefixFilter> in the web.config file will result in only the matching base address for that scheme to be passed through to IIS.

To apply this fix open the web.config file for the service within Visual Studio and within the <system.serviceModel> tags add the following XML:

 

 

<serviceHostingEnvironment>
<baseAddressPrefixFilters>
<add prefix="http://hostname.co.nz/wcfservice"/>
</baseAddressPrefixFilters>
</serviceHostingEnvironment>

 

 

Once these lines are added, redeploy the service and refresh the service in the browser. The error should now be gone.