我想將WCF消息存儲在某些存儲中,稍後再讀取它們以便再次「重放」它們。存儲和重播WCF消息
附加了一些代碼部分:
private void WriteMessage(Message message, string path)
{
FileStream fileStream = new FileStream(path, FileMode.Create);
using (XmlDictionaryWriter writer = XmlDictionaryWriter.CreateBinaryWriter(fileStream))
{
using (XmlDictionaryReader reader = message.GetReaderAtBodyContents())
{
message.WriteBodyContents(writer);
writer.Flush();
}
}
}
private Message ReadMessage(string path)
{
using (FileStream fs = File.OpenRead(path))
{
using (XmlDictionaryReader reader = XmlDictionaryReader.CreateBinaryReader(fs, XmlDictionaryReaderQuotas.Max))
{
fs.Flush();
Message message = Message.CreateMessage(reader, int.MaxValue, messageVersion);
return message.CreateBufferedCopy(int.MaxValue).CreateMessage();
}
}
}
問題是存儲該消息前,Message.ToString()返回的消息字符串,因爲它是想,整個消息,但看完後,該的ToString ()將身體顯示爲「... stream ...」,就是這樣。
請advaice
非常感謝:-)
請注意:在「的WriteMessage」只是身體被讀取和寫入的消息被包裹在另一條消息。
當我使用CreateTextReader/Writer而不是BinaryReader/Writer時,消息被很好地讀取和寫入。 (我不明白它是如何使用BinaryWriter寫的..) – Tamir 2010-08-04 16:25:16