When trying to access a WCF .svc file you may get the following 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
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
The solution, since WCF services hosted in IIS can have only one Base Address was to create a custom service factory to intercept and remove the additional unwanted base addresses that IIS was providing. In my case IIS was providing:
domain.com
www.domain.com
dedicatedserver1234.hostingcompany.com
We are able to customize our .svc file to specif a custom serive factory
We are then able to create our custom factory by inheriting from ServiceHostFactory and overriding as required
class
CustomHostFactory : ServiceHostFactory
{
protected
override
ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
{
CustomHost customServiceHost =
new
CustomHost(serviceType, baseAddresses[1]);
return
customServiceHost;
}
}
class
CustomHost : ServiceHost
{
public
CustomHost(Type serviceType,
params
Uri[] baseAddresses)
:
base
(serviceType, baseAddresses)
{ }
protected
override
void
ApplyConfiguration()
{
base
.ApplyConfiguration();
}
}
In your case, you can decided to pass through baseAddresses[1] (which was the www. address) but it would probably be wise to specify that address you want to prevent changes by your web host from impacting your code.