Supporting Multiple IIS Bindings Per Site


Ref: http://blogs.msdn.com/rampo/archive/2007/06/15/supporting-multiple-iis-bindings-per-site.aspx

How can WCF support multiple IIS Binding specified per site in WCF (.NET Framework 3.0 solution)

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

相关文章:

  • 2021-05-09
  • 2022-03-09
  • 2022-12-23
  • 2021-11-30
猜你喜欢
  • 2021-09-21
  • 2021-05-27
  • 2021-06-02
  • 2021-12-22
  • 2021-09-08
  • 2021-11-08
相关资源
相似解决方案