我忙於C# MQ
,我想在Q上添加文本,但不知道我在做什麼是錯誤的。獲取以下錯誤。MQ推送消息C#
類型的未處理的異常 '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)
{
}
}
}
}
得到MQRC_NOT_AUTHORIZED,在第一個catch。 – 2014-08-28 11:03:46