在同一进程中的多个Windows服务中托管WCF服务
我正在构建一个 Windows 服务来托管 WCF 服务,并且我正在使用:
var ServicesToRun = new ServiceBase[]
{ new Service_1_Host() };
ServiceBase.Run(ServicesToRun);
我的问题是:
如果我有第二个服务及其主机,并且我在上面的代码中添加到数组中,如下所示:
var ServicesToRun = new ServiceBase[] { new Service_1_Host(),
new Service_2_Host() };
ServiceBase.Run(ServicesToRun);
第二个主机是否使用自己的应用程序域运行,或者我必须做一些配置才能使两个主机分别运行它单独的应用程序域?
I am building a windows service to host a WCF service, and I am using :
var ServicesToRun = new ServiceBase[]
{ new Service_1_Host() };
ServiceBase.Run(ServicesToRun);
My question is:
if I have a second service with its host, and I added to the array in the above code, like the following:
var ServicesToRun = new ServiceBase[] { new Service_1_Host(),
new Service_2_Host() };
ServiceBase.Run(ServicesToRun);
does the second host run with its own app domain, or there is some configuration I have to do to make the two hosts run it separate app domain each?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的做法完全错误......您需要区分:
Windows NT 服务(派生自
ServiceBase
),它只是全天候运行实际的 WCF 服务主机(派生自
ServiceHost
),提供真正的 WCF 服务接口。基本上,您需要做的是:
在您的 NT 服务 (
ServiceBase
) 中,有一个OnStart
事件 - 在该事件中,您需要创建并打开您的WCFServiceHost
实例 - NT 服务 (ServiceBase
) 中的每个 WCF 服务(实现)类在该 NT 服务 (
ServiceBase
) 中,有一个OnStop
事件,您应该在其中关闭 WCF 服务主机有些您的代码看起来大致类似于:
然后在您的 NT 服务主应用程序中,您将拥有:
就这样,真的!
You approaching this all wrong.... you need to keep apart:
the Windows NT Service (derived from
ServiceBase
) which is merely here to be running around the clockthe actual WCF service hosts (derived from
ServiceHost
) which provide the real WCF service interfaces.Basically, what you need to do is this:
in your NT Service (
ServiceBase
) there's anOnStart
event - inside that event, you need to create and open your WCFServiceHost
instances - one per WCF service (implementation) classin that NT Service (
ServiceBase
) there's anOnStop
event, inside of which you should close your WCF service hostsSome your code would look roughly something like:
and then in your NT Service main app, you would have:
That's all, really!
请注意,这是一个
ServiceBase
数组,而不是HostsBase
之类的数组。您只需启动多个 Windows 服务即可。这与 WCF 甚至与 AppDomains 无关。Notice that this is an array of
ServiceBase
, not ofHostsBase
or something. You are simply starting up multiple Windows Services. This has nothing to do with WCF or even with AppDomains.