在 C# 中连接到 Websphere MQ 有效,但在 C++ 中失败,代码为 2058 (MQRC_Q_MGR_NAME_ERROR)

Connecting to Websphere MQ in C# works, but fails in C++ with code 2058 (MQRC_Q_MGR_NAME_ERROR)

我需要编写一段代码,使用 C++ 将消息放入 MQ。当我在本地主机上测试它时,使用默认端口 (1414) 它可以工作。但是,在使用特定通道定义和不同端口 (1420) 的实际环境中,它会失败,原因代码为 2058 / MQRC_Q_MGR_NAME_ERROR。 使用 Websphere MQ Explorer 连接到远程 MQ 没有问题。在 C# 应用程序中连接到同一远程服务器以证明连接也没有问题。知道是什么原因造成的吗?

一些示例代码摘录:调用 .connect() 时失败的 C++...

ImqChannel * pChannel_ = 0;  // Channel definition which is at class level
ImqQueueManager queueManager_;   // Queue Manager, also declared at class level


// extract from the MQHelper::Connect() method... 
int MQClient::Connect() {
   pChannel_ = new ImqChannel;
   pChannel_->setChannelName("CLCHL.QM");
   pChannel_->setTransportType(MQXPT_TCP);
   pChannel_->setConnectionName("10.2.3.4(1420)");
   // Should we set this???! pChannel_->setModeName("to what?");

   queueManager_.setName("QM");
   queueManager_.setChannelReference(pChannel_);

   if (!queueManager_.connect()) {
      // ERROR IS HERE: _lastCompletionCode is 2, _lastReasonCode is 2058
      _lastCompletionCode = queueManager_.completionCode();
      _lastReasonCode = queueManager_.reasonCode();
      return (int)_lastReasonCode;
   }
    // If we get here, we're all good:
   return 0;
}

在C#中,没有这样的问题:下面的代码可以正常连接..

queueManager = new MQQueueManager("QM", "CLCHL.QM", "10.2.3.4(1420)");

其他信息:

有什么想法吗?

ImqChannel * pChannel_ = 0;  // Channel definition which is at class level
ImqQueueManager queueManager_;   // Queue Manager, also declared at class level

变量名中多出的下划线是怎么回事?

queueManager_.setName("QM");

这是远程队列管理器的实际队列管理器名称吗?它必须是正确的值。注意:MQ 区分大小写。 IE。 "QM" 与 "qm" 不同。

每个队列管理器的侦听器侦听不同的端口。

pChannel_->setConnectionName("10.2.3.4(1420)");

您确定队列管理器 "QM" 实际上正在侦听端口 1420 而不是 1414、1419 或 1421 等。