Hosting WCF services in IIS is a breeze, however, an interesting error along the lines of:
'This collection already contains an address with scheme http. There can be at most one address per scheme in this collection. Parameter name: item '
According to a response on one of the MSDN forums, "WCF does not support multiple IIS bindings for the same protocol (here it is HTTP) for the same web site". Included in this article is code for creating you own custom service host factory that allows you to get around this.
Download
CustomServiceHostFactory.zip (UPDATE 25/03/2008: As pointed out below by Johan, the custom service host class in the example wasn't needed, just the factory. I've removed it from the example.)
The Code
The code is relatively simple, with the crux of the work being done in the overriden method CreateServiceHost. What would normally happen is that ServiceHosts would be create for all the baseAddresses passed in, which is where WCF comes to a grinding halt.
protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
{
CustomServiceHost customServiceHost;
if (baseAddresses.Length > 1)
customServiceHost = new CustomServiceHost(serviceType, baseAddresses[1]);
else
customServiceHost = new CustomServiceHost(serviceType, baseAddresses[0]);
return customServiceHost;
}
By checking whether or not there are multiple address, and only choosing one of them, the process continues seemlessly. The code included merely demonstrates how to go about creating your own factory - a good enhancement would be to allow the coder to specificy which address, either by index or address, he would actually like to choose.
Once you have your factory included in your WCF service project (the project with the .svc files), its important to modify the svc files to include the factory information in the ServiceHost tag:
<%@ServiceHost Factory="CustomServiceHostFactory" language=c# Debug="true" Service="MyService, MyServiceAssembly" %>
Now you can continue using IIS as your hosting platform for WCF.