Initializing Auto-Start WCF/Workflow Services

AppFabric AutoStart feature is built on top of IIS 7.5 AutoStart feature. IIS 7.5 provides an extensibility point where you can specify your custom initialization providers which will be executed as part of application start-up and gives you the ability to perform costly initialization. For example, pre-populating an AppFabric cache.

Windows Server AppFabric uses this extensibility point to implement the AutoStart feature for WCF & Workflow Services (XAMLX). As part of AppFabric installation, it registers a custom AutoStartProvider which is responsible for activating all the services configured for AutoStart. Here is a simple flow diagram…

imageActivation of WCF/Workflow Services results in calling the ServiceHostFactory associated with the service to return an instance of the ServiceHost which would ultimately host the service and make it available to the clients. This behaviour opens up an option where you could put your costly initialization inside the custom ServiceHostFactory directly rather than using the IIS 7.5 extensibility. CreateServiceHost method of your custom factory will be invoked as soon as AppFabric auto starts your service.

 public class CustomXamlxHostFactory : WorkflowServiceHostFactory     
 {
       protected override WorkflowServiceHost CreateWorkflowServiceHost(WorkflowService service, Uri[] baseAddresses)

        {

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

            // Initialization logic: Populate AppFabric cache etc..

            return host;

        }

}

In .NET 4.0, a custom ServiceHostFactory can be easily associated with a service using the <serviceActivations> element in the web.config.

image

Check out my earlier post for additional details…

Original post by Zulfiqar Ahmed on 26th November 2010 here: https://zamd.net/2010/11/26/initializing-auto-start-wcfworkflow-services/