We have a Web Role that we are hosting in Windows Azure that uses an old ASMX based Web Reference to contact an external system. The Web Reference proxy code is big enough
I like the solution from Steve Marx.
Add this lines to ServiceDefinition.csdef:
<Startup>
<Task commandLine="startup\disableTimeout.cmd" executionContext="elevated" />
</Startup>
And add disableTimeout.cmd in a folder called startup, with the following line of code:
%windir%\system32\inetsrv\appcmd set config -section:applicationPools -applicationPoolDefaults.processModel.idleTimeout:00:00:00
Original solution from here: http://blog.smarx.com/posts/controlling-application-pool-idle-timeouts-in-windows-azure
When running in the emulator please read this: http://blog.smarx.com/posts/skipping-windows-azure-startup-tasks-when-running-in-the-emulator
It looks like the Application_Start handler in Global.asax gets executed when the Web Role is deployed (for ASP.NET) and not on the first request, so that will work for us.
Since the only purpose of a VM hosting a Web Role on Windows Azure is to answer web requests, I would suppose such to sort of tuning to be the responsibility of the Cloud OS, not the Cloud App. That being said, it might interesting to check whether the Azure Cloud OS is indeed making such a tuning available by default.
An update on this, the article below shows how to configure a Windows Azure WebRole
:
http://fabriccontroller.net/blog/posts/iis-8-0-application-initialization-module-in-a-windows-azure-web-role/
You can install the module in a startup batch script using:
PKGMGR.EXE /iu:IIS-ApplicationInit
Then in the WebRole (I've adapted this to work with a WebRole hosting multiple websites):
public class WebRole : RoleEntryPoint
{
public override void Run()
{
using (var serverManager = new ServerManager())
{
// The foreach ensures we enable initialization for all websites hosted on this WebRole.
foreach (var application in serverManager.Sites.SelectMany(x => x.Applications))
{
application["preloadEnabled"] = true;
}
foreach (var applicationPool in serverManager.ApplicationPools)
{
applicationPool["startMode"] = "AlwaysRunning";
}
serverManager.CommitChanges();
}
base.Run();
}
public override bool OnStart()
{
// For information on handling configuration changes
// see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357.
return base.OnStart();
}
}