[英]Reading MSMQ Messages in Raw XML
我试图读取MSMQ消息的原始XML并将其保存到XML文件。 例如,带有正文的MSMQ消息:
<?xml version="1.0"?>
<string>Hello World! I am message #4</string>
我想采用那些确切的xml行并将它们保存到文件message.xml中。
我的消息如下所示:
msg = queue.PeekById(enumerator.Current.Id);
msg.Formatter = new XmlMessageFormatter(new String[] { "System.String,mscorlib" });
System.IO.File.WriteAllText(dirPath + @"\" + msg.Label.Replace(@"\","").Replace(@".","") + enumerator.Current.Id.Replace(@"\","").Replace(@".","") + "_" + DateTime.Now.ToString("MMddyyyyhhmmss") + ".xml", msg.Body.ToString());
queue.ReceiveById(enumerator.Current.Id);
logEntry("*-Received Message with Id " + msg.Id + " and Label " + msg.Label);
但这只是拉文本“Hello World!我是消息#4”,我想要完整的xml。
尝试这个:
msg.Formatter = new ActiveXMessageFormatter();
reader = new StreamReader(msg.BodyStream);
var msgBody = reader.ReadToEnd(); // This gets the actual message as text
格式化程序不需要是对称的 - 您可以在队列的任何一端使用不同的格式化程序。
从这里 - http://andypiper.co.uk/2006/03/31/receiving-plain-text-messages-in-msmq/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.