托管宿主 WCF MSMQ 服務啟動時報錯:「There was an error opening the queue. Ensure that MSMQ is installed and running...」。核心原因在於預設 NetMsmqBinding 安全模式與 ExactlyOnce 特性與環境不符。
var queBinding = new NetMsmqBinding(NetMsmqSecurityMode.None);
queBinding.ExactlyOnce = false;
queBinding.Security.Message.ClientCredentialType = MessageCredentialType.UserName;
host.AddServiceEndpoint(typeof(IWCFMSMQService), queBinding, queBaseAddress);
if (host.State != CommunicationState.Opening) host.Open();
NetMsmqSecurityMode.None:關閉傳輸/訊息層安全,適合內網測試或已有傳輸層加密環境;ExactlyOnce = false:關閉「僅一次投遞」保證,避免需 MSMQ Active Directory 整合的交易式佇列需求;MSDN 論壇討論串 確認修改安全模式即可解決。