WCF分布式開發常見錯誤(19):There was an error opening the queue打開消息隊列出錯
在調試托管宿主 WCF MSMQ消息隊列代碼的時候出現錯誤:
There was an error opening the queue. Ensure that MSMQ is installed and running, the queue exists and has proper authorization to be read from. The inner exception may contain additional information.
打開隊列有一個錯誤,確保MSMQ已經安裝或者運行,隊列存在和有讀權限。異常內部也許包含額外的信息。
解決辦法:
NetMsmqBinding queBinding = new NetMsmqBinding(NetMsmqSecurityMode.None);
queBinding.ExactlyOnce = false;
queBinding.Security.Message.ClientCredentialType = MessageCredentialType.UserName;
// 添加服務終結點
host.AddServiceEndpoint(typeof(WCFService.IWCFMSMQService), queBinding, queBaseAddress);
//判斷是否以及打開連接,如果尚未打開,就打開偵聽端口
if (host.State !=CommunicationState.Opening)
host.Open();
注意:
1. NetMsmqBinding queBinding = new NetMsmqBinding(NetMsmqSecurityMode.None);消息無安全模式;
2. queBinding.ExactlyOnce = false;綁定消息只能讀取一次的屬性設置為false;
3.使用 host.AddServiceEndpoint(typeof(WCFService.IWCFMSMQService), queBinding, queBaseAddress);
添加終結點。
注意配置文件裡的設置注銷掉,只使用代碼來設置,最後啟動宿主即可。
參考文章:
http://social.msdn.microsoft.com/forums/en-US/wcf/thread/7ceeb231-2ff4-4431-9d61-dc071b916788
老外也遇到這個問題,討論的也比較多,但是我修改了安全模式才解決掉。