A couple months ago I wrote a post on how to host WCF services in IIS that expose themselves as endpoints on the Windows Azure AppFabric Service Bus.  The principal challenge in this scenario is that IIS/WAS relies on message-based activation and will only launch the host after the first request comes in.  However, until the host is launched the service will not connect to the Service Bus, and consequently will never receive a message.  A classic catch-22.

The solution I proposed was to leverage the Application Warm-Up Extension for IIS 7.5, which will proactively load and initialize processes before the first request arrives.  While this is acceptable, I’ve found a better solution using the Windows Server AppFabric Autostart (thanks to conversations with Ron Jacobs).

Windows Server AppFabric Autostart is a feature introduced in Windows 7 and Windows Server 2008 R2.  The primary use cases are for reducing the latency incurred by the first message and to host WCF transports/protocols for which their are no listener adapters.  As you can see, initializing the host so that it connects to the Service Bus is another benefit.

To set this up, ensure that you have installed Windows Server AppFabric on your machine.  I personally recommend you use the Web Platform Installer to do this for you (I detail how to do this in the first part of my post on Getting Started with Windows Server AppFabric Cache).  Once you have this installed, follow these steps:

  1. Open IIS Manager.  Navigate to your web application.
  2. Click on Configure in Actions pane.
  3. Configure the application to either autostart all the services by choosing Enabled or specific services by choosing Custom.
  4. If you specified Custom, navigate to the configuration panel for that specific service and turn autostart to Enabled.

Pretty straightforward.  I think you’ll like this solution, as it keeps everything within the AppFabric family.

  • Pingback: Host WCF Services in IIS with Service Bus Endpoints | Wade Wegner

  • Richard Hadley

    I just wanted to thank you for taking the time to post this screencast as it presents a viable solution to a problem I’ve been pondering all day.

    Many thanks
    Richard.

  • Richie Scott

    Hi Wade,

    I want to Host WF (WorkFlow) Services in IIS with Service Bus Endpoints – I managed to get your sample to work with no problems whatsoever but what ever I try I cannot expose a Workflow service as a service bus endpoint.

    Basically I create a new Workflow Service Activity (.xamlx), add a simple sequence, then expose the service as a .svc endpoint:

    ServiceHost Service=”MyActivity.xamlx” Factory=”System.ServiceModel.Activities.Activation.WorkflowServiceHostFactory,System.ServiceModel.Activation,Version=4.0.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35″

    I have then taken your web.config and amended it so that it references my .svc.

    Finally I then host within IIS and configure the service so that it AutoStarts using the instructions you outline above.

    When I view the xxx.servicebus.windows.net endpoint nothing is discovered.

    When I view the endpoints for the Service in IIS (under Services, View Endpoint (for the .svc)) there is only one endpoint and that is the default endpoint created for a workflow service, i.e. a namedPipe.

    Can you shed any light into what I am doing wrong???

    Thanks
    Richie

  • Gustavo

    Wade,

    Is it possible to use the auto start feature of ASP.NET 4.0 to start up a WCF service as used in:

    http://weblogs.asp.net/scottgu/archive/2009/09/15/auto-start-asp-net-applications-vs-2010-and-net-4-0-series.aspx