我忙于C# MQ
,我想在Q上添加文字,但不确定我做的是不是错了。得到以下错误。
未处理的类型' System.NullReferenceException' 发生在Data.Manager.dll中,发生在 " Put1Queue.Put(myPutMessage,Put1PutMsgOptions);"
以下是代码:
class Program
{
static void Main(string[] args)
{
MQ mq = new MQ();
Console.Read();
}
}
public class MQ
{
private MQQueue queue;
private MQMessage queueMessage;
private MQQueueManager queueManager;
private string queueManagerName;
private string host;
private int port;
private string channel;
private string queueName;
public String putMsg;
public String markerMsg;
private MQQueueManager Put1QueueManager;
private MQPutMessageOptions Put1PutMsgOptions;
private MQQueue Put1Queue;
private MQQueueManager Put2QueueManager;
private MQPutMessageOptions Put2PutMsgOptions;
private MQQueue Put2Queue;
private MQQueueManager myQueueManager;
private MQPutMessageOptions myPutMsgOptions;
private MQQueue myQueue;
private Hashtable queueProperties;
public MQ()
{
setupTestData();
}
public void setupTestData()
{
markerMsg = "<msglamdav5_xml><system message_id=\"\" message_type=\"\" correlation_id=\"\" date_time_stamp=\"\" originator=\"\" destination=\"\" queue_manager=\"\" txn_req_number=\"\" txn_req_id=\"\"/><security user_name=\"G9022O2 \" user_type=\"\" user_identity=\"G90226K \" user_language=\"\" environment=\"PPEX \" host_name=\"\"/><errors/><data><txn_ctl bus_txn_phase=\"3\" bus_txn_session_id=\"\" /><data_key party_no=\"0\"/><tasks><task txn_id=\"MARK<uniqueNum> \" event_type=\"2\" external_txn_id=\"04255841252012-06-22-04.56.14.960000 \"><task_data><servicedata inputdata=\"0124473471\"/></task_data><task_metadata><lists/></task_metadata></task></tasks></data></msglamdav5_xml>";
try {
// Setup connection information
MQEnvironment.Hostname = "SLHUBQ2.sanlam.co.za";
MQEnvironment.properties.Add(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES_CLIENT);
MQEnvironment.properties.Add(MQC.CCSID_PROPERTY, 437);
MQEnvironment.Channel = "CLIENTS";//"EFL.SRVCONN";
MQEnvironment.Port = 1615;//lr.eval_int("<Port>");
Put1QueueManager = new MQQueueManager("SLHUBQ2");
int openOptions = MQC.MQOO_OUTPUT | MQC.MQOO_INQUIRE | MQC.MQOO_FAIL_IF_QUIESCING;
Put1Queue = Put1QueueManager.AccessQueue("LAMDA.PERF.REQUEST", openOptions, null, null, null);
Put1PutMsgOptions = new MQPutMessageOptions();
Put1PutMsgOptions.Options = MQC.MQPMO_NEW_MSG_ID | MQC.MQPMO_NEW_CORREL_ID;
}
catch (Exception error)
{
}
try {
MQMessage myPutMessage = new MQMessage();
myPutMessage.ClearMessage();
myPutMessage.Persistence = MQC.MQPER_PERSISTENT;
myPutMessage.Persistence = MQC.MQPER_NOT_PERSISTENT;
myPutMessage.CorrelationId = MQC.MQCI_NONE;
myPutMessage.MessageId = MQC.MQMI_NONE;
myPutMessage.Format = MQC.MQFMT_STRING;
myPutMessage.ReplyToQueueName= "LAMDA.PERF.RESPONSE";
myPutMessage.WriteString(markerMsg);
Put1Queue.Put(myPutMessage, Put1PutMsgOptions);
}
catch (MQException error)
{
}
try
{
Put1Queue.Close();
Put1QueueManager.Disconnect();
}
catch (Exception error)
{
}
}
}
}
答案 0 :(得分:1)
问题可能在您的代码行中
Put1Queue = Put1QueueManager.AccessQueue("LAMDA.PERF.REQUEST", openOptions, null, null, null);
可能是&#39; AccessQueue&#39;方法返回&#39; null&#39;结果。所以你可以尝试检查:
MQC.MQOO_OUTPUT + MQC.MQOO_FAIL_IF_QUIESCING
选项。答案 1 :(得分:0)
如何在每个catch语句中打印出异常,因为我打赌你在AccessQueue上得到了RC 2035,因此Put1Queue对于Put方法是null。 即。
catch (MQException mqex)
{
System.Console.Out.WriteLine("MQException cc=" + mqex.CompletionCode + " : rc=" + mqex.ReasonCode);
}
catch (System.IO.IOException ioex)
{
System.Console.Out.WriteLine("IOException ioex=" + ioex);
}
catch (Exception ex)
{
System.Console.Out.WriteLine("Exception ex=" + ex);
}