自动启动在Azure上WebRole一个WCF [英] AutoStart a WCF on Azure WebRole
问题描述
我有托管在Azure上(WebRole)一个WCF。这WCF做了很多的后台任务和回复一些上访。
I have a WCF hosted on Azure (WebRole). That WCF does a lot of background tasks and replies to some petitions.
问题是,如果WCF没有收到任何申请时间长(10小时以上)的应用程序池被回收的蔚蓝实例和WCF任务停止。我做了一个小调查,一个我可以启用自动启动功能触摸machine.config中,但这不是一个蔚蓝的部署选项。
The problem is that if the WCF doesn't receive any petition for a long time (10 hours or more) the application pool is recycled on the azure instance and the WCF tasks stops. I did a little investigation an I can enable a AutoStart feature touching the machine.config, but this is not an option with a azure deploy.
我可以启用自动启动的web.config中或部署配置文件?
Can I enable AutoStart within web.config or deploy config files?
推荐答案
您可以在WebRole.cs添加一些code修改应用程序池:
You can add some code in the WebRole.cs to modify the application pool:
public class WebRole : RoleEntryPoint
{
public override void Run()
{
using (var serverManager = new ServerManager())
{
var mainSite = serverManager.Sites[RoleEnvironment.CurrentRoleInstance.Id + "_Web"];
var mainApplication = mainSite.Applications["/"];
var mainApplicationPool = serverManager.ApplicationPools[mainApplication.ApplicationPoolName];
mainApplicationPool["autoStart"] = true;
mainApplicationPool["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();
}
}
注意::要使用 ServerManager的
你将需要:
- 引用的 C:\\ WINDOWS \\ SYSTEM32 \\ INETSRV \\ Microsoft.Web.Administration.dll (或可通过的NuGet)
- 添加
<运行时的ExecutionContext =架空/>
在你的服务定义的WebRole元素
- reference C:\Windows\system32\inetsrv\Microsoft.Web.Administration.dll (or available through NuGet)
- add
<Runtime executionContext="elevated" />
in your Service Definition under the WebRole element
这篇关于自动启动在Azure上WebRole一个WCF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!