Supporting Multiple IIS Bindings Per Site


If you see this error when you are hosting in IIS then most probably you have multiple IIS bindings per scheme in your web site. WCF in .Net Framework 3.0 ,out of the box, does not support multiple binding per site, but this can enabled by extending the System.ServiceModel.Activation.ServiceHostFactory,  and providing a CustomServiceHostFactory. CustomServiceHostFactory  picks the appropriate base address for the application.  The Factory attribute in the ServiceHost directive is set to the CustomSerivceHostFactory.

The only drawback is every developer hosting their application will need to change the svc file to provide the CustomServiceHostFactory, which picks the appropriate base address.


Sample Code

public class MultipleIISBindingSupportServiceHostFactory : ServiceHostFactory


protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)


      Uri[] requiredAddress = GetAppropriateBase(baseAddresses);

      return base.CreateServiceHost(serviceType, requiredAddress);




Uri[] GetAppropriateBase(Uri [] baseAddresses)


        List<Uri> retAddress = new List<Uri>();

        foreach (Uri address in baseAddresses)


            if (address.DnsSafeHost == "localhost")






return retAddress.ToArray();



In the svc file, fill in the Factory attribute

<%@ServiceHost Factory="NS.MultipleIISBindingSupportServiceHostFactory" Service="CalculatorService" %>

Comments (6)
  1. I am currently working on the new Tech Head Brothers authoring tool THBAuthoring as you can read in this

  2. Background IIS has web sites, which are containers for virtual applications which contain virtual directories.

  3. Background IIS has web sites, which are containers for virtual applications which contain virtual directories

  4. [WCF] This collection already contains an address with scheme http…

  5. Calling a WCF Service from Silverlight 2.0: Part Two

  6. As a self-confessed crayon wielder I tend not to get involved in the washing machine technology of web

Comments are closed.

Skip to main content