Condividi tramite


Custom ServiceHostFactory for a XAMLX based Service

For IIS/WAS hosted services backed by a physical .SVC file (WCF 3.0/3.5) you can specify a custom ServiceHostFactory in the .svc file as part of service specification. There is no such declaration for XAMLX files and instead you can use config-based activation feature to achieve the same result.

If my WCF service is deployed as Service1.xamlx and I want to customize the WorkflowServiceHost before it’s opened and used, I can easily do this using following two steps:

  1. Create a custom ServiceHostFactory by sub classing the default one

namespace DeclarativeServiceLibrary1

{

    public class MyServiceHostFactory : WorkflowServiceHostFactory

    {

        protected override WorkflowServiceHost CreateWorkflowServiceHost(Activity activity, Uri[] baseAddresses)

        {

            return base.CreateWorkflowServiceHost(activity, baseAddresses);

        }

        protected override WorkflowServiceHost CreateWorkflowServiceHost(WorkflowService service, Uri[] baseAddresses)

        {

            var host = base.CreateWorkflowServiceHost(service, baseAddresses);

            // add your customizations here…

            return host;

        }

    }

}

2.  Configure your custom ServiceHostFactory for your XAMLX file

  <system.serviceModel>

    <serviceHostingEnvironment multipleSiteBindingsEnabled=“true“ >

      <serviceActivations>

        <add relativeAddress=“~/Service1.xamlx”

             service=“Service1.xamlx”

             factory=“DeclarativeServiceLibrary1.MyServiceHostFactory“/>

      </serviceActivations>

    </serviceHostingEnvironment>

  </system.serviceModel>

 

Originally posted by Zulfiqar Ahmed on 23 April 2010 here https://zuahmed.wordpress.com/2010/04/23/custom-servicehostfactory-for-a-xamlx-based-service-2/

Comments

  • Anonymous
    June 01, 2010
    We have WCF web services on IIS7 (.NET 3.5) with the Shared Configuration (NLB) and would like to have the ability to make requests to each of the web servers to confirm each server is responding to requests. Historically, we have just add a binding on each server to the IP of one of the NIC's that allowed us to accomplish this. We have our web services setup to use the Custom ServiceHostFactory but when I add the multipleSiteBindingsEnabled="true"  to the serviceHostingEnvironment node, I get the following validation error: "The 'multipleSiteBindingsEnabled' attribute is not declared." Do I have to make some other declaration in the web.config for this attribute to be recognized in this schema?

  • Anonymous
    June 25, 2010
    Hi, Try the following: • RUN VS2010 command prompt • Re-register ASP.net: aspnet_regiis.exe –i • Re-register WCF: ServiceModelReg.exe -ia • Make sure AppPool is configured to use .Net 4.0