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/