如何使用 c#.net 与 ibm websphere mq 建立连接
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9339062/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to get connect with ibm websphere mq by using c#.net
提问by shannu
can any one guide me on, to get connect with ibm websphere mq by using c#.net, reason was i am trying to push the message in to MQ, kindly can any give me suggestion to connect by using c#.net
任何人都可以指导我,通过使用 c#.net 与 ibm websphere mq 连接,原因是我试图将消息推送到 MQ,请任何人给我建议使用 c#.net 连接
回答by nybbler
There is an IBM supplied dll (since v5.3 Fixpack8) on Windows called amqmdnet.dll, which is a .NET assembly providing an IBM supported model for MQSeries. (Reference) It is usually located in C:\Program Files\IBM\WebSphere MQ\bin\amqmdnet.dll
在 Windows 上有一个 IBM 提供的 dll(自 v5.3 Fixpack8 起),称为 amqmdnet.dll,它是一个 .NET 程序集,为 MQSeries 提供 IBM 支持的模型。(参考)它通常位于C:\Program Files\IBM\WebSphere MQ\bin\amqmdnet.dll
If you need more direction, there are several examples on how to communicate with MQ from .NET on CodeProject:
如果您需要更多指导,这里有几个关于如何在 CodeProject 上从 .NET 与 MQ 通信的示例:
- http://www.codeproject.com/Articles/12198/IBM-WebSphere-MQ-with-C-GUI-application-that-is-bo
- http://www.codeproject.com/Articles/37807/How-to-Setup-a-Websphere-MQ-with-C-NET-GUI-to-Put
- http://www.codeproject.com/Articles/6212/C-and-WebSphere-MQ-formerly-MQSeries-Client-Server
- http://www.codeproject.com/Articles/12198/IBM-WebSphere-MQ-with-C-GUI-application-that-is-bo
- http://www.codeproject.com/Articles/37807/How-to-Setup-a-Websphere-MQ-with-C-NET-GUI-to-Put
- http://www.codeproject.com/Articles/6212/C-and-WebSphere-MQ-original-MQSeries-Client-Server
Also, there's this walkthrough that could be helpful: http://www.c-sharpcorner.com/UploadFile/pk_khuman/AquickstartCsharpWebsphereMQ07112006024017AM/AquickstartCsharpWebsphereMQ.aspx
此外,还有一个可能有帮助的演练:http: //www.c-sharpcorner.com/UploadFile/pk_khuman/AquickstartCsharpWebsphereMQ07112006024017AM/AquickstartCsharpWebsphereMQ.aspx
回答by Shashi
There are number of samples that come with MQ product install. Refer Nmqsput.cs for your case. When creating a new project you will need to add amqmdnet.dll as reference.
MQ 产品安装附带了许多示例。请参阅 Nmqsput.cs 以了解您的情况。创建新项目时,您需要添加 amqmdnet.dll 作为参考。
Not sure what version of MQ you are using. I am assuming you are using MQ v701. You can find the samples under tools folder of your MQ installation.
不确定您使用的是什么版本的 MQ。我假设您使用的是 MQ v701。您可以在 MQ 安装的工具文件夹下找到示例。
If are looking for JMS style of messaging in C#, then XMS .NETis worth looking at. You can find the samples of XMS .NET in the same folder as MQ samples. XMS .NET reference is here
如果在 C# 中寻找 JMS 风格的消息传递,那么XMS .NET值得一看。您可以在与 MQ 示例相同的文件夹中找到 XMS .NET 的示例。XMS .NET 参考在这里
回答by Danny
You can connect using the .NET libraries provided by IBM; however, they require you to install the WebSphere MQ Client on every server you deploy your solution to. (lame)
您可以使用 IBM 提供的 .NET 库进行连接;但是,它们要求您在部署解决方案的每台服务器上安装 WebSphere MQ 客户端。(瘸)
If using WebSphere MQ, the machine used to run the XMS application must be installed with the WebSphere MQ Client V7.0.1.0 or later
如果使用 WebSphere MQ,则用于运行 XMS 应用程序的机器必须安装 WebSphere MQ Client V7.0.1.0 或更高版本
You can avoid this by converting a few Java libraries using IKVM (www.ikvm.net).
您可以通过使用 IKVM (www.ikvm.net) 转换一些 Java 库来避免这种情况。
The whole process should only take about 15 minutes.
整个过程应该只需要大约15 分钟。
You'll still need to download and install the client on your development box so that you can get the JAR files. After you convert them, you can uninstall the client.
您仍然需要在您的开发盒上下载并安装客户端,以便您可以获得 JAR 文件。转换它们后,您可以卸载客户端。
Here are the steps
以下是步骤
1) Get JARs
1) 获取 JAR
- Download WebSphere MQ V7.5 Client: http://www-304.ibm.com/support/docview.wss?uid=swg24032744
- Install the MQ client: You only need to install the "Java and .Net Messaging and Web Services".

- 下载 WebSphere MQ V7.5 客户端:http://www-304.ibm.com/support/docview.wss?uid=swg24032744
- 安装 MQ 客户端:您只需要安装“Java 和 .Net 消息传递和 Web 服务”。

2) Convert JARs
2) 转换 JAR
- Download IKVM: www.ikvm.net
- Extract the IKVM files (e.g. c:\tools\IKVM).
- Open Win command prompt
- Execute command: set path=%path%;c:\tools\IKVM\bin
- Execute command: cd C:\Program Files (x86)\IBM\WebSphere MQ\java\lib
- Execute command: ikvmc -target:library -sharedclassloader { com.ibm.mq.jmqi.jar } { com.ibm.mqjms.jar } { dhbcore.jar } { jms.jar }
- 下载 IKVM:www.ikvm.net
- 提取 IKVM 文件(例如 c:\tools\IKVM)。
- 打开 Win 命令提示符
- 执行命令:set path=%path%;c:\tools\IKVM\bin
- 执行命令:cd C:\Program Files (x86)\IBM\WebSphere MQ\java\lib
- 执行命令:ikvmc -target:library -sharedclassloader { com.ibm.mq.jmqi.jar } { com.ibm.mqjms.jar } { dhbcore.jar } { jms.jar }
3) Copy JARs
3) 复制 JAR
- Open windows explorer.
- Navigate to: C:\Program Files (x86)\IBM\WebSphere MQ\java\lib
- Copy the following files:
- **com.ibm.mq.jmqi.dll
- com.ibm.mqjms.dll
- jms.dll**
- Navigate to: c:\tools\IKVM\bin
- Copy the following files:
- **IKVM.Runtime.dll
- IKVM.OpenJDK.Core.dll**
- Move the copied files to a 3rd Partyfolder in your project/solution.
- 打开 Windows 资源管理器。
- 导航到:C:\Program Files (x86)\IBM\WebSphere MQ\java\lib
- 复制以下文件:
- **com.ibm.mq.jmqi.dll
- com.ibm.mqjms.dll
- jms.dll**
- 导航到:c:\tools\IKVM\bin
- 复制以下文件:
- **IKVM.Runtime.dll
- IKVM.OpenJDK.Core.dll**
- 将复制的文件移动到项目/解决方案中的3rd Party文件夹。
4) References JARs
4) 引用 JAR
- Reference the copied JARs. Please note that you can skip the previous Copy JARsstep above and simply reference the libraries directly, if you like. The objective was to show that there were no other resources needed for proper execution.

- 引用复制的 JAR。请注意,如果您愿意,您可以跳过前面复制 JAR步骤,直接直接引用库。目的是表明正确执行不需要其他资源。

The following is a very simple example of how you can use the libraries.
下面是一个非常简单的示例,说明如何使用这些库。
using com.ibm.msg.client.jms;
using com.ibm.msg.client.wmq.common;
using javax.jms;
using System;
class Program
{
static void Main(string[] args)
{
var ff = JmsFactoryFactory.getInstance(JmsConstants.__Fields.WMQ_PROVIDER);
var cf = ff.createConnectionFactory() as JmsConnectionFactory;
cf.setIntProperty(CommonConstants.__Fields.WMQ_CONNECTION_MODE, CommonConstants.__Fields.WMQ_CM_CLIENT);
cf.setStringProperty(CommonConstants.__Fields.WMQ_HOST_NAME, "<YOUR INFO>");
cf.setIntProperty(CommonConstants.__Fields.WMQ_PORT, 1414);
cf.setStringProperty(CommonConstants.__Fields.WMQ_CHANNEL, "<YOUR INFO>");
cf.setStringProperty(CommonConstants.__Fields.WMQ_QUEUE_MANAGER, "<YOUR INFO>");
var connection = cf.createConnection();
var session = connection.createSession(false, Session.__Fields.AUTO_ACKNOWLEDGE);
var queue = session.createQueue("queue:///<YOUR INFO>");
var producer = session.createProducer(queue);
var msg = session.createTextMessage();
msg.setStringProperty("JMSXGroupID", Guid.NewGuid().ToString());
msg.setIntProperty("JMSXGroupSeq", 1);
msg.setBooleanProperty("JMS_IBM_Last_Msg_In_Group", true);
msg.setText("Hello World");
connection.start();
producer.send(msg);
producer.close();
session.close();
connection.close();
}
}

