Tuesday, April 17, 2012

WCF service error: This collection already contains an address with scheme https. There can be at most one address per scheme in this collection.

After moving some WCF services from one server to another, I was welcomed by the following error message:
"This collection already contains an address with scheme https. There can be at most one address per scheme in this collection."
“Googling” the error brought me a solution soon, but what caused this error message?
The solution
You can resolve this error by changing the web.config file.
With ASP.NET 4.0, add the following lines to your web.config:
<system.serviceModel>
 <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>

With ASP.NET 2.0/3.0/3.5, add the following lines to your web.config:
<system.serviceModel>
 <serviceHostingEnvironment>
  <baseAddressPrefixFilters>
   <add prefix="https://dev.server.be"/> 
  </baseAddressPrefixFilters>
 </serviceHostingEnvironment>
</system.serviceModel>

The reason
IIS has web sites, which are containers for virtual applications which contain virtual directories. The application in a site can be accessed through one or more IIS binding.

IIS bindings provide two pieces of information – binding protocol and binding information. Binding protocol defines the scheme over which communication occurs, and binding information is the information used to access the site.


Example
Binding protocol – HTTP
Binding Information – IPAddress , Port, Hostheader
The problem is that the IIS server was configured to support multiple bindings, which results in multiple base addresses per scheme. This brings WCF into trouble. A WCF service hosted under a site allows binding to only one baseAddress per scheme.

2 comments:

Aníbal Germán Camía said...

Thank you so much! It helped me a lot! :)

Rashad Rivera said...

What if you don't want multiple bindings? I'm using Windows 2012 and it does not seem to work, but rather now gives a "specify a relative uri for endpoint." I think more explanation is necessary when dealing with different IIS and/or OS environments. This (in my opinion), is a major short coming for the WCF team.