4
votes

I am new to MSMQ and am trying to send an XML message to a remote transactional queue. Both machines are 2003 server. I can get it to work with a non-transactional remote queue. I can't seem to get the messages to drop on the transactional queue. The C# code is below. I do not get an error it just never appears.

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);
1

1 Answers

4
votes

You could create the transaction explicitly.

using (var transaction = new MessageQueueTransaction())
{
    transaction.Begin();
    rqQueue.Send(rqMessage, transaction);
    transaction.Commit();
}

For the overload you're using, perhaps you don't have the "direct format name" and that option is unsupported. MSDN