Sunday, April 17, 2011

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

Recently, I deployed my fully tested WCF service to a shared hosting environment and I was greeted by this nasty message the first time I tried to test my service by entering the url in the address bar. Upon researching the issue I realized that my ISP had allowed my service to be accessible using multiple host names. Obviously, I did not have access to their IIS, so had to come up with an alternate solution. In my solution, I created a custom ServiceHostFactory and forced WCF to use this host factory.

1. Create a new class that inherits from the ServiceHostFactory.
2. Override the CreateServiceHost, create a new servicehost type with the Uri of that you want the service to bind to and return the new servicehost from the CreateServiceHost method.
 3. Change the .svc file of your service to use the new custom service host that you have created. This is done by providing the namespace name of your servicehost in the Factory attribute of the .svc file.


Hope this helps.