tags:

views:

336

answers:

4

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?

+4  A: 

You can specify the startup order using the serivce dependency. That is stop the WCF service from starting before the MSMQ service. See: http://serverfault.com/questions/84181/can-the-startup-order-for-windows-services-be-configured-if-so-where

Shiraz Bhaiji
I went for this solution. Thank you
Kristoffer
A: 

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.

jmservera
+1  A: 
ServiceInstaller serviceInstaller = new ServiceInstaller();


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

serviceInstaller.ServicesDependedOn = new string[] { "MSMQ" };
Daniel Vassallo
A: 

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.

Pratik