我是MSMQ的新手,正在尝试将XML消息发送到远程事务队列。两台计算机均为2003服务器。我可以通过非事务性远程队列使其工作。但我似乎无法让消息落在事务队列上。下面是C#代码。我没有收到错误提示,消息似乎从未出现过。
Message rqMessage = new Message();
System.Xml.Serialization.XmlSerializer ser = new System.Xml.Serialization.XmlSerializer( typeof([message type]));
XmlTextWriter writer = new XmlTextWriter(rqMessage.BodyStream, Encoding.UTF8);
ser.Serialize(writer, rqDoc);
rqMessage.Label = "message label";
rqMessage.TimeToBeReceived = Message.InfiniteTimeout;
rqMessage.TimeToReachQueue = Message.InfiniteTimeout;
rqMessage.ResponseQueue = new MessageQueue("Path");
rqMessage.Formatter = new ActiveXMessageFormatter();
MessageQueue rqQueue = new MessageQueue(nodeRequestQueue.SelectSingleNode("Path").InnerText);
bool transactional = false;
try
{
transactional = rqQueue.Transactional;
}
catch(MessageQueueException)
{
transactional = false;
}
if ( transactional )
rqQueue.Send(rqMessage, MessageQueueTransactionType.Single);
else
rqQueue.Send(rqMessage);
MessageQueueTransaction
是IDisposable
,因此将其使用包装在using
语句中是一个好习惯。我已相应地更新了答案。 - Alexander Stepaniuk