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. foreach的使用

    //foreach循环语句,常用来遍历数组,一般有两种使用方法:不取下标,取下标 //不取下表 foreach(数组 as 值) { //执行的程序 echo 值; } //取下标 foreach(数 ...

  2. leetcode326

    public class Solution { public bool IsPowerOfThree(int n) { && ( % n == ); } } https://leetc ...

  3. leetcode349

    public class Solution { public int[] Intersection(int[] nums1, int[] nums2) { var list1 = nums1.ToLi ...

  4. android -chrome 调试

    在chrome上 输入 chrome://inspect/ 连接手机,配置 监听8000,和8080端口 cordova默认是8000端口 如果出现白屏:原因:google在首次加载时,要进行服务器连 ...

  5. 5.15 python 面向对象的软件开发&领域模型

    1.面向对象的软件开发 参考地址::http://www.cnblogs.com/linhaifeng/articles/6182264.html#_label14 面向对象的软件工程包括下面几个部: ...

  6. UI5-文档-4.20-Aggregation Binding

    现在我们已经为我们的应用建立了一个良好的结构,是时候添加更多的功能了.通过添加一些JSON格式的发票数据,我们开始探索数据绑定的更多特性,这些发票数据显示在面板下面的列表中. Preview A li ...

  7. XML学习记录1-复习SAX,DOM和JAXB

    对xml文档的解析常见的有JDK中的sax,dom,jaxb,stax和JAVA类库JDOM和DOM4J,下面先说说前三个. Java中解析XML的工具很多,像JDOM,DOM4J等,但Java标准库 ...

  8. 使用innodb_force_recovery解决MySQL崩溃无法重启问题

    因为日志已经损坏,这里采用非常规手段,首先修改innodb_force_recovery参数,使mysqld跳过恢复步骤,将mysqld 启动,将数据导出来然后重建数据库.innodb_force_r ...

  9. Jquery和Ajax

    jQuery 是一个 JavaScript 函数库.JavaScript 是 HTML5 以及所有现代浏览器中的默认脚本语言! jQuery 库包含以下特性: HTML 元素选取 HTML 元素操作 ...

  10. invalid self-signed ssl certificate

    down voteaccepted Cheap and insecure answer: Add process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0& ...