This is an simple example of how to use .NET 2.0 to connect as a client to WebSphere MQ 7.
First, you need to setup a QueueManager, Channel, and Queue on a host and particular port. This may already be done for those lucky enough to have an MQ adminstrator.
Here is a screen shot of what this looks like in WebSphere’s MQ Explorer.
Second, you’ll need to add a reference to the amqmdnet.dll provided by WebSphere. If you installed WebSphere MQ server then you’ll have it already in the bin directory of your WebSphere installation.
The amqmdnet.dll that you reference also references a different dll, amqmdxcs.dll. You must include this in your project bin or wherever you choose to put these dlls.
If you are using the dll’s from WebSphere MQ 7, you’ll be fine. I’ve tested this connection example against both WebSphere 6 and WebSphere 7 (both using version 7′s dlls). However, if you decide to use version 6 dlls you’ll need more dlls than the two mentioned here. You may even have trouble (as I’ve had) using diferent minor versions of the version 6 dlls. So, if you can, use version 7 dlls.
Also note: There are some security features and some event features that are not included in the .NET dlls provided by WebSphere that are used in the java implementations.
Without further ado, the example code for a simple connection to WebSphere MQ using a .NET client:
using System; using IBM.WMQ; // Added reference to "C:\Program Files\ibm\WebSphereMQ\bin\amqmdnet.dll" using System.Collections; namespace TestWebsphereMQ { public class WMQTester { static void Main(string[] args) { // Setup some test data string queueManagerName = "QM_TEST"; string host = "127.0.0.1"; int port = 1415; string channel = "QM_TEST.SVRCONN"; WMQTester tester = new WMQTester(); tester.Connect(queueManagerName, host, port, channel); } public MQQueueManager Connect( string queueManagerName, string host, int port, string channel) { MQQueueManager queueManager; // Setup connection information Hashtable queueProperties = new Hashtable(); queueProperties[MQC.HOST_NAME_PROPERTY] = host; queueProperties[MQC.PORT_PROPERTY] = port; queueProperties[MQC.CHANNEL_PROPERTY] = channel; try { // Attempt the connection queueManager = new MQQueueManager(queueManagerName, queueProperties); Console.WriteLine("Connected Successfully"); } catch (MQException mexc) { // TODO: Setup other exception handling throw new Exception(mexc.Message + " ReasonCode: " + mexc.ReasonCode + "--- see list of Reason Codes at http://russsutton.com/developer/?p=45 " + mexc.StackTrace, mexc); } // For now, return the queueManager to use in reading/writing messages next return queueManager; } } }
Hope that helps! I banged my head on the wall a few times with the different versions of dlls and finding the lack of features in the WebSphere-provided .NET implementation that are readily available in the java implementations.

Hi, I was wondering if there’s any big difference in connecting to a remote machine and sending the messages through that channel? I have the host name, channel name, and queue manager name but I am not sure about the port, how could I find that out? I’ve tried to connect many times but I just keep getting an Exception with reason code 2059 (MQRC_Q_MGR_NOT_AVAILABLE).
I’m using the version 6 of the dll and the remote machine has MQSeries v5.3, might this be an issue?
Thanks,
Jose
Jose,
In production, I’m using the above code example pointed to a remote server rather than 127.0.0.1 and it is working just fine. You may need to talk with your MQ Series administrator if you have one. If YOU have access to your MQ Series server you can navigate to the queue you are trying to connect to and look at its properties to find the port to use.
Do i need to install WebSphere to use the amqmdnet.dll