无法从远程MQ获取消息

时间:2018-07-10 10:02:52

标签: c# ibm-mq

我可以使用我的代码连接到远程MQ,但是无法从远程MQ获取消息。我在收到类似System.TypeInitializationException的错误 queueGetMessageOptions [b]。

请帮助您解决任何有关该问题的线索,或者提供任何文档帮助

enter image description here

我的C#代码

  namespace MQMessageSender
  {
      public class MQTest
      {
           public static void Main()
           {
               ConnectMQ();

           }

           public static int ConnectMQ()
           {
              MQQueueManager queueManager;

              MQMessage queueMessage;
              // MQPutMessageOptions queuePutMessageOptions;
              MQGetMessageOptions queueGetMessageOptions;
              MQQueue queue;
              // Hashtable properties;
              // MQMessage message;

              string QueueName;
              string QueueManagerName;
              string ChannelInfo;
              string channelName;
              string PortNumber;
              string transportType;
              string connectionName;
              //string message;

              QueueManagerName = "*****";
              QueueName = "*******";
              ChannelInfo = "****/*****/*****/*****";
              PortNumber = "****";


              char[] separator = { '/' };
              string[] ChannelParams;
              ChannelParams = ChannelInfo.Split(separator);
              channelName = "*****";
              transportType = "MQC.TRANSPORT_MQSERIES_CLIENT";
              connectionName = "*****(****)";
              String strReturn = "";

              try
              {
                  queueManager = new MQQueueManager(QueueManagerName,
                  channelName, connectionName);
                  strReturn = "Connected Successfully";

                  queue = queueManager.AccessQueue(QueueName,
                  MQC.MQOO_INPUT_AS_Q_DEF + MQC.MQOO_FAIL_IF_QUIESCING);
                  queueMessage = new MQMessage();
                  queueMessage.Format = MQC.MQFMT_STRING;
                  queueGetMessageOptions = new MQGetMessageOptions();
                  queue.Get(queueMessage, queueGetMessageOptions);
                  strReturn = queueMessage.ReadString(queueMessage.MessageLength);
            }
            catch (MQException exp)
            {
                 strReturn = "Exception: " + exp.Message;
            }

           Console.WriteLine(strReturn);
           Console.WriteLine("Press any key to continue . . .");
           Console.ReadLine();
           return 0;
       }

错误:

“ System.Transactions.Diagnostics.DiagnosticTrace”的类型初始值设定项引发了异常。

enter image description here

1 个答案:

答案 0 :(得分:0)

您的配置文件中有问题。异常告诉“无法识别的配置节参数”