我有一个托管 WCF 服务的 Windows 服务。如果我的 WCF 服务真的出了问题,我想停止 Windows 服务。我可以尝试通过 shell out 和使用 net stop 来强制它停止,但是有没有更好的方法来做到这一点?
WCF 以通常的方式从 Windows 服务运行:
protected override void OnStart(string[] args)
{
if (serviceHost != null)
{
serviceHost.Close();
}
///WCF service hosted
serviceHost = new ServiceHost(typeof(XXXService));
serviceHost.Open();
}
最佳答案
过去,我们使用“服务主机 Controller ”类实现自托管 WCF Windows 服务,该类保存对 ServiceHost 对象的引用,因此负责“启动”/打开和“停止”/关闭服务宿主对象。此外,“服务主机 Controller ”类实现了一个委托(delegate),允许托管对象回调到 Controller 并启动正常关闭。
关于c# - 托管 WCF 的 Windows 服务 - 我可以从 WCF 服务中停止 Windows 服务吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19267869/