开发者

Connecting to remote queue manager using C# and .Net

I wrote an application that connected to local queue manager using this function call:

MQQueueManager mqQMgr = new MQQueueManager("QM_QueueManagerName");

Now I need to connect to remote queue ma开发者_高级运维nager on another computer.

I can successfully connect to remote queue manager using MQ Explorer from my development PC using QM_ComputerName as queue manager name, S_ComputerName as channel and ComputerName as connection name. So it is accessible from my desktop.

However, when I try to connect via .Net I get MQRC_Q_MGR_NAME_ERROR no matter what I try.

I tried specifying

MQEnvironment.Hostname = "ComputerName";
MQEnvironment.Channel = "S_ComputerName ";

and then calling

mqQMgr = new MQQueueManager("QM_ComputerName");

I also tried  calling 

mqQMgr = new MQQueueManager("QM_ComputerName", "S_ComputerName", "ComputerName");

I get error in both cases.

Anyone can advise?


This is how I got it to work:

 MQQueueManager mqQMgr=null;

   Hashtable props = new Hashtable();

props.Add(MQC.HOST_NAME_PROPERTY, "HostNameOrIP");

   props.Add(MQC.CHANNEL_PROPERTY, "ChannelName");

   props.Add(MQC.PORT_PROPERTY, 1414); // port number

   props.Add(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES_MANAGED);

   MQQueue mqQueue = null;

   try

   {

      mqQMgr = new  MQQueueManager("QueueManagerName", props);

      mqQueue = mqQMgr.AccessQueue(
               QueueName,
               MQC.MQOO_OUTPUT                   // open queue for output
               + MQC.MQOO_FAIL_IF_QUIESCING);   // but not if MQM stopping
   }

   catch (MQException mqe1)

   {

   }


Perhaps this sample code will help.

I linked to the V7 docs. Ideally you will be using both the V7 client and talking to a V7 server because the .Net functionality is much improved in these over V6. Also, V6 is end-of-life as of September 2011 so it would be good to go straight to v7 now and avoid the upgrade later.

If you need the v7 WMQ client, which includes the updated .Net samples and classes, go to IBM MQ Client Downloads page (requires IBM ID but is a free download).

UPDATE 20180810: Changed link to point to IBM's new page for all IBM MQ client downloads.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜