By connecting to MQSeries withing a .NET application, first it has to be done is to install MQ Series client at the machine which will host the application.
To do that, you can obtain for example the trial
version of WebSphere MQ. During installation first the prerequisites are
checked. Unfortunately if you try to install the package at Windows
Vista, no wonder, it will just fail, because the operative system is
currently not supported by the setup. The good thing is that this
requirement just can be ignored. Clearly that means, just install all
other prerequisites and proceed with installation.

If you
installed the Web Sphere at the local machine or somewhere in the
windows environment with active directory infrastructure, there is a
group named "MQM". The windows user who is running your .NET application
has to be member of this group in order to be able to connect to MQ. In
that case following code can be used to establish the connection and to
put one simple message in the queue:

[TestMethod]
        [Description("Changes the status of one single event."), Owner("ddobric")]
        public void MQ()
        {
            MQQueueManager queueManager = new MQQueueManager("QM_testmgr", "mychannel", "192.168.1.64");
            MQQueue queue = queueManager.AccessQueue("default", MQC.MQOO_OUTPUT + MQC.MQOO_FAIL_IF_QUIESCING);
            MQMessage queueMessage = new MQMessage();

queueMessage.Format = MQC.MQFMT_STRING;
            queueMessage.MessageId = new byte[] { 0x01, 0x02, 0x03, 0x04};
            queueMessage.WriteString("Hello World");

MQPutMessageOptions queuePutMessageOptions = new MQPutMessageOptions();
            queue.Put(queueMessage, queuePutMessageOptions);

}

This
code connects to the MQ manager "QM_testmgr" by using of channel
"mychannel" hostet at the specified IP address. After executing you can
see the message in the queue "default".
Assume you want now to
connect to some remote machine. If you use this code the connection to
the queueManager will fail with reason code 2035 = Not Authorized. To
avoid this problem the MCA of the remote channel
has to be
explicitly set. To do that, open the MQ Explorer go to channel
properties and open the tab MCA. Then enter the name of the user who is
authorized to connect. In the example bellow, I used the user "mqm".

Now the code in the .NET application has to be slightly changed as shown in the next example:

[TestMethod]
        [Description("Changes the status of one single event."), Owner("ddobric")]
        public void MQ()
        {
            Hashtable props = new Hashtable();
            props.Add(MQC.HOST_NAME_PROPERTY, "sopmqseries");
            props.Add(MQC.CHANNEL_PROPERTY, m_ChannelName);
            props.Add(MQC.USER_ID_PROPERTY, "mqm");
            props.Add( MQC.PASSWORD_PROPERTY, "enter anything here." );

MQQueueManager queueManager = new MQQueueManager(m_QueueManager, props);

MQQueue queue = queueManager.AccessQueue("default",
            MQC.MQOO_OUTPUT + MQC.MQOO_FAIL_IF_QUIESCING);
            MQMessage queueMessage = new MQMessage();

queueMessage.Format = MQC.MQFMT_STRING;
            queueMessage.MessageId = new byte[] { 0x01, 0x02, 0x03, 0x04};
            queueMessage.WriteString("Hello World");

MQPutMessageOptions queuePutMessageOptions = new MQPutMessageOptions();
            queue.Put(queueMessage, queuePutMessageOptions);

}

At
this point is important, that specified username "mqm" has to match the
name set in the MCA-tab. Additionally it is interesting, that the
password does not have to match user's password, but it has to be
specified as property.
If password property is not specified at all, the initialization will crash with a "null reference error".

Last
but not least. If you do not want to specify the username in your code,
means you would like to use the first code example, there also one a
little confusing possibility. Create some other user and put in the MQM
group. The name of this user should be the same as the name of user who
will run the .NET application. In this case if the name of interactive
user (who is running the application) matches the name of the user
member of MQM group at the remote system (this does not have to be
necessarily windows system) you will not need the provide credential
properties (MQC.USER_ID_PROPERTY and MQC.PASSWORD_PROPERTY) and MCA name may be empty.

By troubleshooting following very useful link contains the list of all reason codes.

Connecting to MQSeries with .NET的更多相关文章

  1. Error connecting to database [Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (13)]

    参照 http://stackoverflow.com/questions/4448467/cant-connect-to-local-mysql-server-through-socket-var- ...

  2. 两主机搭建MySQL主从复制后,show slave status显示:Last_IO_Error: error connecting to master ……

    两台主机A.B搭建mysql主从复制关系(A为master,B为slave)后,在slave上执行show slave status,结果中显示Last_IO_Error: error connect ...

  3. [nginx] connect() failed (111: Connection refused) while connecting to upstream, client: 101.18.123.107, server: localhost,

    nginx一直报错, 2016/12/02 10:23:19 [error] 1472#0: *31 connect() failed (111: Connection refused)while c ...

  4. connect() failed (111: Connection refused) while connecting to upstream

    配置好lamp后,在浏览器中运行程序后,出现上面的错误. 转自:http://www.xuejiehome.com/blread-1828.html I'm experiencing 502 gate ...

  5. Ipython console in Spyder stuck on “connecting to kernel”

    简短地记录下,今天排除的spyder的BUG, 现象:打开Spyder时其他正常,但是Ipython console 不能正常获取到kernel,一直转圈,显示“connecting to kerne ...

  6. socket() failed (13: Permission denied) while connecting to upstream

    /*************************************************************************** * socket() failed (13: ...

  7. Connecting Physics Bodies

    [Connecting Physics Bodies] The kinds of joints you can create in Sprite Kit. You add or remove join ...

  8. 【转载】MySQL 5.6主从Slave_IO_Running:Connecting/error connecting to master *- retry

    原文地址:MySQL 5.6主从Slave_IO_Running:Connecting/error connecting to master *- retry 作者:忆雨林枫 刚配置的MySQL主从, ...

  9. CCS 5 XDS100 仿真连接错误Error connecting to the target【瓦特芯笔记】

      问题现象:在点击仿真是出现连接错误: Error connecting to the target: (Error -151 @ 0x0) One of the FTDI driver funct ...

随机推荐

  1. PCIe Max_Payload_Size 和 Max_Read_Request_Size

    最近PCIe在SSDFans上镜率挺高,那我们来聊两句MAX_READ_REQUEST_SIZE 和MAX_PAYLOAD_SIZE. 这两个东西都在PCIe Capability Structure ...

  2. solr入门之权重排序方法初探之使用edismax改变权重

    做搜索引擎避免不了排序问题,当排序没有要求时,solr有自己的排序打分机制及sorce字段 1.无特殊排序要求时,根据查询相关度来进行排序(solr自身规则) 2.当涉及到一个字段来进行相关度排序时, ...

  3. Hibernate 和 MyBatis 的对比

    一.开发对比 开发速度 Hibernate 的真正掌握要比MyBatis来的难些.MyBatis框架较轻量级,相对简单很容易上手,但也相对简陋些.个人觉得要用好 MyBatis 还是要首先理解好 Hi ...

  4. WinRAR 代码执行漏洞复现

    影响版本: WinRAR < 5.70 Beta 1 Bandizip    < = 6.2.0.0 好压(2345压缩)    < = 5.9.8.10907 360压缩    & ...

  5. Java反射 - 简单的给Bean赋值和取值

    由于项目的实际需要,所以利用java反射原理写了一个简单给bean赋值和取值通用的类,在此记录下方便自己日后用到,也为需要的兄弟提供个参考例子. 工具类BeanRefUtil:   package c ...

  6. linux系统下修改文件夹目录权限-chmod

    Linux.Fedora.Ubuntu修改文件.文件夹权限的方法差不多.很多人开始接触Linux时都很头痛Linux的文件权限问题.这里告诉大家如何修改Linux文件-文件夹权限.以主文件夹下的一个名 ...

  7. leetcode138

    /** * Definition for singly-linked list with a random pointer. * struct RandomListNode { * int label ...

  8. Simple2D-24 Sprite 渲染树

    如果要开发游戏,单单使用 Painter 绘制图片会变得十分复杂.如果使用 Sprite 对象进行显示,可以简单地实现图片的位移.旋转和缩放,结合 Action 对象可以实现复杂的动画效果.最重要的是 ...

  9. JS 判断鼠标滚轮的上下滚动

    JS 判断鼠标滚轮的上下滚动   <script type="text/javascript"> var scrollFunc = function (e) { e = ...

  10. (转载)session token机制

    http://blog.chinaunix.net/uid-26642709-id-3061264.html 使用session token时,必须用struts2表标签库,不能用html 通过ses ...