Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MSMQ backed WCF service hosted in a windows service fails on startup

I have a WCF service hosted in a Windows service that I set to Automatic so it will start automatically when the server is brought up. The service is endpoint is MSMQ backed.

When I start the service manually, everything is good. But when the service starts on bootup, I get a MSMQ exception:

System.TypeInitializationException: The type initializer for
'System.ServiceModel.Channels.Msmq' threw an exception. ---> 
System.ServiceModel.MsmqException: The version check failed with the error: 
'The Message Queuing service is not available (-1072824309, 0xc00e000b)'. The 
 version of MSMQ cannot be detected All operations that are on the queued channel
 will fail. Ensure that MSMQ is installed and is available.
   at System.ServiceModel.Channels.MsmqQueue.GetMsmqInformation
                   (Version& version, Boolean& activeDirectoryEnabled)
   at System.ServiceModel.Channels.Msmq..cctor()
   --- End of inner exception stack trace ---

It seems like the MSMQ is not ready to be used before the service starts...is there a solution to this?

like image 425
puffpio Avatar asked Dec 18 '09 18:12

puffpio


People also ask

What is MSMQ in WCF?

The MsmqToWcf sample demonstrates how a Message Queuing (MSMQ) application can send an MSMQ message to a Windows Communication Foundation (WCF) service. The service is a self-hosted console application to enable you to observe the service receiving queued messages.


1 Answers

You need to add a dependency on MSMQ in your WCF service host. You can do this in the service installer:

ServiceInstaller serviceInstaller = new ServiceInstaller();
// Adding this property to your ServiceInstaller forces 
// your service to start after MSMQ.
serviceInstaller.ServicesDependedOn = new string[] { "MSMQ" };

If you are not using a service installer, you can also add the MSMQ dependency for your service by editing the Windows registry, as described in "Microsoft Support: How to delay loading of specific services".

like image 126
Daniel Vassallo Avatar answered Oct 17 '22 00:10

Daniel Vassallo