已鎖定 AppFabric Service Auto-Start

  • Tuesday, April 10, 2012 4:14 PM
     
     

    I want to take advantage of IIS 7.5 application pool auto-start feature for my web application.  In 'applicationhost.config' file, I made the following changes:

    1) set startMode="AlwaysRunning" for the application pool

    2) set serviceAutoStartEnabled="true" for the application.

    Now when I kill/terminate w3wp process in Task Manager, I can see it spawning again right away. But it does not invoke Application_Start event in my application's Global.asax file. I thought setting serviceAutoStartEnabled="true" starts application as well.

    Does 'serviceAutoStartEnabled' belong to IIS 7.5 auto-start or AppFabric auto-start?


    MP


    • Edited by Maulik Patel Wednesday, April 11, 2012 12:25 AM
    •  

All Replies

  • Wednesday, April 11, 2012 2:11 PM
     
     
    Has anyone encountered this problem before?

    MP

  • Thursday, April 12, 2012 10:23 AM
     
     
  • Thursday, April 12, 2012 12:09 PM
     
     

    Thanks Purvi.

    The URL that you gave me talks about using AppFabric's auto-start feature. I do not want to use AppFabric for certain reasons. I want to use IIS 7.5's auto-start feature.

    So I am curious whether 'serviceAutoStartEnabled' is supported by IIS 7.5 or not.


    MP

  • Monday, April 16, 2012 4:20 PM
     
     

    In other words, my question is:

    What happens if I use only 'serviceAutoStartEnabled' and do NOT specify 'serviceAutoStartProvider' for an IIS application? Which piece of code will be invoked when IIS application pool recycles in this case? Will it invoke Application_Start method in Global.asax?


    MP

  • Monday, April 16, 2012 5:01 PM
     
     Answered Has Code

    Hello Maulik,

    The autostart feature in IIS 7.5 is effectively a feature of WAS. The AutoStart feature of WAS works fine when self-hosting because you have control over theinstantiation of your ServiceHost. When hosting in IIS you can't control your servicehost itself so WAS can't do much with it.
    In order to make your service capable of WAS activation you should define your own ServiceHost and a ServiceHostFactory (O Reilly Programming WCF page 19).

    Also see

    http://msdn.microsoft.com/en-us/library/system.servicemodel.activation.servicehostfactory.aspx

    http://msdn.microsoft.com/en-us/library/system.servicemodel.servicehost.aspx

    I also give you some sample coding of myself (which works, but I also have AppFabric installed).

    svc-file

    <%@ ServiceHost Language="C#" Debug="true" Factory="WhiteRebel.AutoStart.Host.AutoStartHostFactory" Service="WhiteRebel.AutoStart.Host.AutoStart" %>
    

    ServiceHostFactory

    	public class AutoStartHostFactory : ServiceHostFactory
    	{
    		#region constructors
    		public AutoStartHostFactory()
    		{
    		}
    		#endregion
    		#region public overrides
    		public override ServiceHostBase CreateServiceHost(string constructorString, Uri[] baseAddresses)
    		{
    			return this.CreateServiceHost(typeof(AutoStart), baseAddresses);
    		}
    		#endregion
    		#region protected overrides
    		protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
    		{
    			EventManager.WriteInformation("CreateServiceHost");
    			AutoStartHost result = new AutoStartHost(serviceType, baseAddresses);
    			EventManager.WriteInformation("Host instance created");
    			return result;
    		}
    		#endregion
    

    ServiceHost

    	public class AutoStartHost : ServiceHost
    	{
    		#region constructors
    		public AutoStartHost()
    		{
    		}
    		public AutoStartHost(object singletonInstance, params Uri[] baseAddresses)
    			: base(singletonInstance, baseAddresses)
    		{
    		}
    		public AutoStartHost(Type serviceType, params Uri[] baseAddresses)
    			: base(serviceType, baseAddresses)
    		{
    		}
    		#endregion
    		#region protected overrides
    		protected override void ApplyConfiguration()
    		{
    			EventManager.WriteInformation("AutoStartHost.ApplyConfiguration invoked");
    			base.ApplyConfiguration();
    		}
    		protected override ServiceDescription CreateDescription(out IDictionary<stringContractDescription> implementedContracts)
    		{
    			EventManager.WriteInformation("AutoStartHost.CreateDescription invoked");
    			return base.CreateDescription(out implementedContracts);
    		}
    		#endregion
    	}
    

    Don't take to much notice of the EventManager class. That's simply a helper-class for writing to a custom log and eventsource.
    Using the EventLog is very handy to find out what's actually happening and in what sequence.

    If it still doesn't work you might try to configure the default AutoStartProvider.
    First run this command on the server to check for any AutoStartProviders.

    C:\Windows\system32\inetsrv\appcmd.exe list CONFIG /section:system.applicationHost/serviceAutoStartProviders /config:*

    If none defined run this script to activate the default AutoStartProvider

    SET PGM=C:\Windows\system32\inetsrv\appcmd.exe
    REM * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
    REM * Create an entry for the AutoStartProvider and assign the type
    REM * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
    %PGM% set CONFIG /section:system.applicationHost/serviceAutoStartProviders /+[name='Service']
    %PGM% set CONFIG /section:system.applicationHost/serviceAutoStartProviders /[name='Service'].type:"Microsoft.ApplicationServer.Hosting.AutoStart.ApplicationServerAutoStartProvider, Microsoft.ApplicationServer.Hosting, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

    You can't do this with a single command.

    Good Luck

    Nico

    • Marked As Answer by Maulik Patel Monday, April 16, 2012 5:51 PM
    •