使用.Net连接到IBM WebSphere MQ会引发错误MQRC_NOT_AUTHORIZED

时间:2017-04-20 11:54:07

标签: .net ibm-mq

我是MQ的新手,并尝试在我的机器上配置它。要求是设置MQ,以便我可以使用我的C#.NET代码在MQ中作为消息发送/接收XML文件。我在我的机器上安装了IBM WebSphere MQ 9.0版本。据我所知,到目前为止,我需要至少设置队列管理器,队列和通道来实现这一目标。所以我试着在我的MQ中设置它们。但是,当我尝试运行我的代码时,我收到错误“MQRC_NOT_AUTHORIZED”。

有人可以指导我设置这些东西,以便通过.NET进行文件共享的方案有效吗?我想在这种情况下客户端和服务器都将在我的机器上本地?创建队列,频道等时有很多参数可供选择,这让我感到困惑,我想我在设置中选择了不正确的定义。

这是我的.Net代码:

using IBM.WMQ;
using System;
using System.Collections;

namespace MQTest
{

class MQTest
{
    public MQQueueManager ConnectMQ()
    {
        MQQueueManager queueManager;

        // Setup connection information                  
        Hashtable queueProperties = new Hashtable();
        queueProperties[MQC.HOST_NAME_PROPERTY] = "localhost";
        queueProperties[MQC.PORT_PROPERTY] = 1414;
        queueProperties[MQC.CHANNEL_PROPERTY] = "QM._TEST.SVRCONN";

        try
        {
            // Attempt the connection
            queueManager = new MQQueueManager("QM_TEST", queueProperties);
            Console.WriteLine("Connected Successfully");
        }
        catch (MQException mexc)
        {
            // TODO: Setup other exception handling
            throw new Exception(mexc.Message
                       + " ReasonCode: " + mexc.ReasonCode
                       + mexc.StackTrace, mexc);
        }

        // For now, return the queueManager to use in reading/writing messages next
        return queueManager;
    }
 }
}

以下是我的MQ设置的快照:

队列管理员 Queue Manager

队列 enter image description here

频道 enter image description here

监听 enter image description here

1 个答案:

答案 0 :(得分:1)

  

AladdinMQ.LOCAL.ONE

首先,使用混合大小写MQ对象是个坏主意。你只是在寻找麻烦。如果不使用引号,MQ喜欢大写MQ对象。因此,最好只使用大写的MQ对象名称。

如果您的UserId不在mqm组中,那么您需要授予UserId权限以(1)访问队列管理器和(2)访问队列。

可以通过'Group'而不是'UserId'来执行MQ权限。假设该组需要访问以“AladdinMQ”开头的队列。以下是用于设置OAM权限的setmqaut命令:

setmqaut -m QM_TEST -t qmgr -g {GROUP} +connect +inq +dsp
setmqaut -m QM_TEST -n AladdinMQ.** -t queue -g {GROUP} +allmqi +dsp

其中{GROUP}是UserId所属的组的名称。