c# - 托管 WCF 的 Windows 服务 - 我可以从 WCF 服务中停止 Windows 服务吗?

标签 c# wcf service

我有一个托管 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/

相关文章:

c# - 如何在歌曲中存储评分?

visual-studio-2008 - 有状态的 WCF Web 服务

c# - 如何使用 WCF 在 WSSE 安全 header 中设置密码类型 "PasswordText"

java - 使用 Windows 服务调用使用 JNI 和 LoadLibrary 的 Java 程序的问题

android - 手机关机时会调用onDestroy吗?

c# - 如何创建消除重复代码的函数

c# - 数据注释 - DisplayFormat - 格式化数字字符串

java - 创建需要用户参数的 OSGI 服务

c# - 如何制作 2 个 0 边距的内联元素?

wcf - 有了 WCF 为什么还需要服务总线?