简体   繁体   English

Windows服务启动顺序导致WCF服务中的错误状态

[英]Windows service start order causes faulted state in WCF Service

I have a WCF service hosted as a Windows service. 我有一个WCF服务托管为Windows服务。 The WCF service uses msmq queue on the same server. WCF服务在同一服务器上使用msmq队列。

When the server is restarted my WCF service starts before the msmq service. 重新启动服务器后,我的WCF服务先于msmq服务启动。 This puts my WCF service in faulted state. 这使我的WCF服务处于故障状态。

What is the best way to handle this? 处理此问题的最佳方法是什么? Should I set up a dependency to the msmq service? 我应该建立对msmq服务的依赖吗? Is there a way to handle this from the wcf service? 有什么办法可以从wcf服务中解决此问题?

You can specify the startup order using the serivce dependency. 您可以使用serivce依赖关系指定启动顺序。 That is stop the WCF service from starting before the MSMQ service. 那就是停止WCF服务从MSMQ服务之前启动。 See: https://serverfault.com/questions/84181/can-the-startup-order-for-windows-services-be-configured-if-so-where 请参阅: https//serverfault.com/questions/84181/can-the-startup-order-for-windows-services-be-configured-if-so-where

ServiceInstaller serviceInstaller = new ServiceInstaller();


// Adding this property to your ServiceInstaller forces 
// your service to start after MSMQ.

serviceInstaller.ServicesDependedOn = new string[] { "MSMQ" };

您可以在设计时在NamedServiceInstaller类中执行此操作,并在想要之前启动的每个服务的ServicesDependedOn属性中添加一个带有服务名称的字符串。

If you are on windows server 2008 setting the service startup type to Automatic (Delayed Start) may be another option. 如果您在Windows Server 2008上,则将服务启动类型设置为“自动(延迟启动)”可能是另一种选择。 This will start MSMQ service before your WCF hosting service. 这将在WCF托管服务之前启动MSMQ服务。
But I think the Shiraj's answer for setting dependencies is better. 但是我认为Shiraj对于设置依赖项的答案更好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM