在Windows服务中托管的MSMQ支持的WCF服务在启动时失败

时间:2009-12-18 18:32:36

标签: wcf windows-services msmq startup

我在Windows服务中托管了一个WCF服务,我将其设置为“自动”,因此它将在服务器启动时自动启动。该服务是端点是MSMQ支持。

当我手动启动服务时,一切都很好。但是当服务在启动时启动时,我得到一个MSMQ异常:

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 ---

似乎MSMQ还没有准备好在服务开始之前使用......有解决方案吗?

1 个答案:

答案 0 :(得分:7)

您需要在WCF服务主机中添加对MSMQ的依赖关系。您可以在服务安装程序中执行此操作:

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

如果您没有使用服务安装程序,还可以通过编辑Windows注册表来为服务添加MSMQ依赖项,如“Microsoft Support: How to delay loading of specific services”中所述。