Auto-Start Feature

The auto-start feature of AppFabric is built on top of the auto-start feature of Internet Information Services (IIS) 7.5, which is included in Windows 7 and Windows Server 2008 R2. In IIS, you can configure an application pool and all or some of its applications to automatically start when the IIS service starts. The AppFabric auto-start feature extends this functionality so that you can configure all or some of the services within an application to automatically start when the application starts.

Benefits of the Auto-Start Feature

When you enable the auto-start feature for a service, the service is up and running as soon as the application that it belongs to is started and before the service receives the first WCF message from the client. Therefore, the service processes the first message quickly because it is already initialized. For example, suppose a service needs to connect to a database to read hundreds of rows of data to populate a .NET Framework caching data structure when it is first created. The initialization processing takes a long time before the service is ready to begin the actual operation. If you use auto-start in this case, the service is initialized before it receives the first call.

The HTTP.SYS component of IIS processes HTTP requests, and the Windows Process Activation service (WAS) processes TCP, Named Pipes, and MSMQ requests by using custom WCF listener adapters that are included with IIS. The listener adapter establishes communication between WAS and a service that uses non-HTTP protocols. To support processing messages received over another protocol, you have to develop custom listener adapters and other supporting modules, which can be a complex task. For more information about listener adapters, see Listener Adapters (https://go.microsoft.com/fwlink/?LinkId=160359). With auto-start support, you can deploy applications that support any protocol to IIS. If you enable auto-start for these deployed applications, WAS activates them and keeps them active in the worker process.

Auto-Start Scenarios

Services that use the auto-start feature support scenarios like the following:

  • The computer on which an application is deployed is rebooted. IIS, WAS, application pool, application, and services are configured to automatically start with the computer. The services are automatically started in this scenario when the application is restarted. If the application is configured to automatically start all services, all the services within the application are automatically started; otherwise, only the services specified in the Web.config file are started.

  • Some protocols, such as the WS-Discovery announcement protocol, require applications to be always available. When you enable auto-start for an application and services in the application, the Windows Server AppFabric auto-start feature automatically starts the services whenever the application containing the services is started.

  • The application pool that a service belongs to detects that too many of its worker processes have become unhealthy in a specified period of time and initiates the rapid-fail protection process. The auto-start feature supports rapid-fail protection in that if a process fails more than a configurable number of times within a specified time period, the application and its services will not restart after the rapid-fail protection threshold has been crossed.

Computer Restart Scenario

The following list contains typical steps involved in a computer-restart sample scenario that the auto-start feature supports:

  1. The Windows Process Activation service (WAS) starts if the service is configured to start automatically. You can configure WAS by using the Services applet in Administrative Tools.

  2. WAS starts all the application pools that are configured to start automatically. The startMode setting on these application pools is set to AlwaysRunning in the ApplicationHost.config file.

    <applicationPools>
        <add name=”MyAppPool” startMode=”AlwaysRunning” />
    </applicationPools>
    
  3. The application manager within WAS loads all the applications that are configured to start automatically. The serviceAutoStartEnabled attribute is set to true for these applications in the ApplicationHost.config file.

    <sites>
        <site name="MySite" id="1">
            <application path="/"  serviceAutoStartEnabled=”true” serviceAutoStartProvider=”Service” serviceAutoStartMode=”All/Custom”>
                <virtualDirectory path="/" physicalPath="C:\MySite" />
            </application>
        </site>
    </sites>                
    
  4. The application initialization process invokes the auto-start module, which starts the services that are configured to start automatically.

    The serviceAutoStartProvider attribute is an IIS extensibility point, which you can use to start custom objects. The Windows Server AppFabric installation program installs the Service provider and extends the IIS schema to add the serviceAutoStartMode attribute.

    If the serviceAutoStartMode for an application is set to All, then all the services in the application are started. If the serviceAutoStartMode setting for an application is set to Custom, only the services specified in the Web.config file are started.

    The auto-start module uses the value of the relativeVirtualPath setting to load a service. The following configuration fragment is from a Web.config file that has relativeVirtualPath settings configured for two services. The relativeVirtualPath of a service is the path to the service relative to the application containing the service.

    // a sample Web.config fragment with two services configured to use the auto-start feature.
    <Microsoft.ProcessServer.Hosting>
        <serviceAutoStart>
            <add relativeVirtualPath =”/Calendar/Appointments.xamlx” >
            <add relativeVirtualPath =”/BookStore/ShoppingCart.svc” >
        </serviceAutoStart>
    </Microsoft.ProcessServer.Hosting>
    

    Tip

    Auto-start settings for services are stored in the Web.config file, and auto-start settings for application pools and applications are stored in the ApplicationHost.config file.

Configuring Auto-Start

You can use IIS Manager extensions or cmdlets that AppFabric provides to configure the auto-start feature for a WCF or WF service. For detailed step-by-step instructions to configure the auto-start feature, see the Configure Auto-Start Using IIS Manager and Configure Auto-Start Using Windows Server AppFabric Cmdlets topics in the Configuring Auto-Start section.

Note

If the auto-start feature is enabled for a service, IIS ignores the Idle Timeout setting on the application pool and on the application that uses the application pool. The worker process associated with the application pool remains in memory even after the application pool is idle for longer than the Idle Timeout value.

Warning

If the initialization code is inefficiently written for a service and the initialization takes a long time, the IIS startup time period may expire and shut down the process in its current state. A good design decision might be to use multiple threads from within the initialization code for your service if it is running on computers with more than one CPU.

See Also

Concepts

Configuring Auto-Start