【问题标题】:Communicate with a Windows Service using ServiceController class使用 ServiceController 类与 Windows 服务通信
【发布时间】:2011-12-21 16:17:28
【问题描述】:

我有一个 Windows 服务项目,它由两个服务 service1 和 service2 组成。我们如何在两个服务之间进行通信?例如,我们如何让 service2 由 service1 启动?我可以使用 ServiceController 类来执行此操作吗?你会建议怎么做?

【问题讨论】:

    标签: c# .net windows windows-services servicecontroller


    【解决方案1】:

    ServiceController 类包括一个采用 int 的 ExecuteCommand 方法。因此,如果您可以使用非常有限的参数,那么您的两个服务可以通过相互发送 ExecuteCommand 消息来进行通信。

    但是,作为其他海报cmets,WCF 可能是一个更好的答案。您可以在两个服务之间创建命名管道或使用 HTTP。可以在下面找到两个很好的教程页面。

    Basic WCF Tutorial with examples

    More complex WCF, if you wanted to 'fake' delegates for example

    希望对您有所帮助。

    【讨论】:

      【解决方案2】:

      如果“通信”是指启动和停止 Service2,那么应该使用 ServiceController

      如果您需要其他类型的通信,例如将一些数据从一个发送到另一个,ServiceController 将无济于事,您应该使用WCF

      希望对你有帮助

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-05-25
        • 1970-01-01
        • 1970-01-01
        • 2012-01-24
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多