简体   繁体   中英

Windows service start order causes faulted state in WCF Service

I have a WCF service hosted as a Windows service. The WCF service uses msmq queue on the same server.

When the server is restarted my WCF service starts before the msmq service. This puts my WCF service in faulted state.

What is the best way to handle this? Should I set up a dependency to the msmq service? Is there a way to handle this from the wcf service?

You can specify the startup order using the serivce dependency. That is stop the WCF service from starting before the MSMQ service. See: 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. This will start MSMQ service before your WCF hosting service.
But I think the Shiraj's answer for setting dependencies is better.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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