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. django路由初识

    静态文件配置 1.项目下面新建一个文件夹static settings.py中最后添加 STATICFILES_DIRS = [ os.path.join(BASE_DIR, "static ...

  2. web.py尝试性学习!

    首先导入web.py模块! import web 没有的话就: pip install web web.py的URL结构: urls = ( '/', "index" ) 第一部分 ...

  3. HTML5 学习之地理定位

    html5 获取坐标: <!DOCTYPE HTML> <html> <head> <title>test1.html</title> &l ...

  4. leetcode138

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

  5. leetcode367

    public class Solution { public bool IsPerfectSquare(int num) { , high = num; while (low <= high) ...

  6. win2008安装IIS

    win2008安装IIS http://jingyan.baidu.com/article/fec4bce2398747f2618d8b88.html http://127.0.0.1/ 新建网站,端 ...

  7. VB6 让程序结束后带有返回值

    第三方命令行程序运行完之后,批处理中可以随时通过errorlevel变量收取运行结果.而VB写的控制台程序却没有提供这样的功能.关于让控制台程序返回值的教程是本博客独家放出. 返回值,其实也就是进程的 ...

  8. 基于OpenGL编写一个简易的2D渲染框架-02 搭建OpenGL环境

    由于没有使用GLFW库,接下来得费一番功夫. 阅读这篇文章前请看一下这个网页:https://learnopengl-cn.github.io/01%20Getting%20started/02%20 ...

  9. Gulp的安装与配置

    http://blog.csdn.net/itlsx/article/details/49981459

  10. ArrayList 原理(2)

    1. 概述 关于Java集合的小抄中是这样描述的: 以数组实现.节约空间,但数组有容量限制.超出限制时会增加50%容量,用System.arraycopy()复制到新的数组,因此最好能给出数组大小的预 ...