WCF学习笔记(七):WAS寄宿MSMQ的那些事儿

当使用WAS寄宿MSMQ的时候,即使用net.msmq协议的时候,会出现很多错。这是因为使用MSMQ需要比其他协议配置更多的地方。。。

首先,如果你要做一个关于MSMQ的demo,我推荐大家使用“化零为整WCF(16) - 消息队列(MSMQ - MicroSoft Message Queue)”里边的示例。推荐理由:示例简单明了。

其次,必须为IIS安装non-HTTP组件,并且为WCF Service应用程序开启net.msmq支持,否则会出现以下错误:

Could not find a base address that matches scheme net.msmq for the endpoint with binding NetMsmqBinding. Registered base address schemes are [http].

第三,在服务管理中打开相关的服务,比如“Net.Msmq Listener Adapter”

第四,必须穿件与虚拟路径相同的消息队列,并将IIS_USRS加入其ACL列表。其实这一点最为重要,是我想要着重说的一点。例如你的Web地址是http://localhost/WcfSrvDemo42/MSMQService.svc,那么你要再localhost也就是本机上创建private(或者public等)类型的消息队列,路径应该是:“private$\WcfSrvDemo42/MSMQService.svc”。创建完成之后,还需要将IIS_USRS加入其ACL列表中。具体方法是,右击刚刚创建的消息队列,选择属性,在安全选项卡中添加IIS_USRS用户,并在下面的详细权限中至少选择“Recieve Message”和“Peek Message”,如果只是演示,简单起见,可以选择“Full Control”。如果第四点没有配置好,就会出现以下错误:

An error occurred while opening the queue:The queue does not exist or you do not have sufficient permissions to perform the operation. (-1072824317, 0xc00e0003). The message cannot be sent or received from the queue. Ensure that MSMQ is installed and running. Also ensure that the queue is available to open with the required access mode and authorization.

一般来说,大家遇到第四点错误的几率比较大。这个时候一方面要检查是否创建了MQ并且给了权限,另一方面可以尝试重新生产WCF Service的代码并部署。这两方面都做了,应该这个错误就解决了。祝大家好运。

原文地址:https://www.cnblogs.com/ceachy/p/WCF_WAS_MSMQ.html