2009-12-18 133 views
9

我有一個WCF服務託管在Windows服務中,我將其設置爲自動,以便在服務器啓動時自動啓動。服務端點是MSMQ支持的。MSMQ支持的Windows服務中託管的WCF服務在啓動時失敗

當我手動啓動服務時,一切都很好。但是,當服務在啓動時啓動,我得到一個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不準備在服務啓動之前使用...有一個解決的辦法?

回答

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」描述。

+0

謝謝!谷歌的異常消息證明是徒勞的! – puffpio