开发者

Windows service start order causes faulted state in WCF Service

开发者 https://www.devze.com 2022-12-14 16:07 出处:网络
I have a WCF service hosted as a Windows service. The WCF service uses msmq queue on the same server.

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? Shou开发者_JS百科ld 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" };


You can do this in your NamedServiceInstaller class at design time, add a string with the name of the service in the ServicesDependedOn property for each service you want to be started before.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号