WCF分布式开发常见错误(19):There was an error opening the queue打开消息队列出错

来源:互联网 发布:北京银行学知支行 编辑:程序博客网 时间:2024/06/05 11:47
Posted on 2009-06-17 00:39 Frank Xu Lei 阅读(1429) 评论(9)  编辑 收藏 网摘 所属分类: WCF分布式开发常见错误

    在调试托管宿主 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

老外也遇到这个问题,讨论的也比较多,但是我修改了安全模式才解决掉。

 


 

【老徐的博客】

【作者】:Frank Xu Lei

【地址】:http://www.cnblogs.com/frank_xl/archive/2009/06/17/1504695.html

 

原创粉丝点击