[英]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.