Here is the detailed and verified solution for Bootstrapping application in on start of application pool
Note: This approach requires minimum IIS 7.5 and .NET 4 and managedPipelineMode="Integrated" for Application Pool
Add below class in WCF Service
-----------------------------------------------------------------------------------------------------
namespace MyWCFService // add this class in WCF Service
{
public class MyWCFServiceWarmup : System.Web.Hosting.IProcessHostPreloadClient
{
public void Preload(string[] parameters)
{
CRMService service = CRMService.GetService(); //crm service singleton initialzation
}
}
}
-----------------------------------------------------------------------------------------------------
Open Command Prompt and write below Commands
cd c:\windows\system32\inetsrv\config
notepad applicationHost.config
----------------------------------------------------
Edit applicationHost.config
1. Find your Application Pool Entry under Configurations
2. Add managed startMode="AlwaysRunning" refer below example
------------------------------------------------------------------------------------------------------
<applicationPools>
<add name="MyWCFServicePool" autoStart="true" managedRuntimeVersion="v4.0" managedPipelineMode="Integrated" startMode="AlwaysRunning">
<processModel identityType="NetworkService" />
</add>
</applicationPools>
3. Find your Application under sites -> site
4. Add serviceAutoStartEnabled="true" serviceAutoStartProvider="MyWCFServicePreLoad" refer below example
-------------------------------------------------------------------------------------------------------
<sites>
<site name="MyWCFService" id="12" serverAutoStart="true">
<application path="/" applicationPool="MyWCFServicePool" serviceAutoStartEnabled="true" serviceAutoStartProvider="MyWCFServicePreLoad">
<virtualDirectory path="/" physicalPath="C:\Services\MyWCFService" />
</application>
</site>
</sites>
5. Then Add below tag after </sites> .
---------------------------------------------------------------------------------------------------------
<serviceAutoStartProviders>
<add name="MyWCFServicePreLoad" type="MyWCFService.MyWCFServiceWarmup, MyWCFService" />
</serviceAutoStartProviders>
---------------------------------------------------------------------------------------------------------
6. Save applicationHost.config
This will initiate first instance Singleton class when Application Pool starts instead of first request hit.
Restart WCF Service and then Application Pool in IIS.