Welcome to MSDN Blogs Sign in | Join | Help

Supporting Multiple IIS Bindings Per Site

MultiplBinding

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")

            {

               retAddress.Add(address);

             }

 

         }

return retAddress.ToArray();

 }

}

In the svc file, fill in the Factory attribute

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

Published Friday, June 15, 2007 12:59 AM by Ram Poornalingam
Filed under: ,

Comments

# Issue with WCF Services hosted in IIS using multiple bindings per site

Wednesday, August 01, 2007 1:26 PM by Laurent Kempé

I am currently working on the new Tech Head Brothers authoring tool THBAuthoring as you can read in this

# How can WCF support multiple IIS Binding specified per site ?

Monday, February 11, 2008 4:53 PM by Ram Poornalingam's WebLog

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

# How can WCF support multiple IIS Binding specified per site ?

Monday, February 11, 2008 5:05 PM by Noticias externas

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

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

Friday, May 09, 2008 12:34 PM by Corrado's BLogs

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

# Calling a WCF Service from Silverlight 2.0: Part Two

Friday, August 15, 2008 6:32 AM by Cynot Why Not

Calling a WCF Service from Silverlight 2.0: Part Two

# Publishing WCF web services for Silverlight.

Wednesday, November 19, 2008 9:26 AM by PsiSpace by Simon Middlemiss

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

Anonymous comments are disabled
 
Page view tracker