简体   繁体   English

存储和重播WCF消息

[英]Store And Replay WCF Messages

I want to store WCF messages in some storage and read them later on in order to "replay" them again. 我想将WCF消息存储在某些存储中,并稍后再阅读以再次“重播”它们。

Attached some code parts: 附加了一些代码部分:
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();
}
}
}

problem is that before storing the message, the Message.ToString() returns the message string as it's should like, the whole message, but after reading it, the ToString() shows the body as "... stream ..." and that's it. 问题在于,在存储消息之前,Message.ToString()返回所需的消息字符串,即整个消息,但是在读取消息后,ToString()将主体显示为“ ...流...”,并且而已。

please advaice 请注意
Many thanks :-) 非常感谢 :-)

Please note: at the "WriteMessage" only the body is read and written as the message is wrapped in another message. 请注意:在“ WriteMessage”中,由于将消息包装在另一条消息中,因此仅读取和写入正文。

Have a look at Charles , you can easily store a session and then play it again or even edit individual requests and change the hostname, etc. We use it to generate test sessions, save them, and then replay the sessions with bots to generate a useful load test. 看看Charles ,您可以轻松地存储会话,然后再次播放它,甚至编辑单个请求并更改主机名,等等。我们用它来生成测试会话,保存它们,然后使用机器人重播这些会话以生成一个会话。有用的负载测试。

The only downside is the evaluation version only works for 30 mins, but hey, if you use it all the time then it's well worth the 50 bucks the full license cost. 唯一的缺点是评估版只能使用30分钟,但是,嘿,如果您一直使用它,那么50美元的完整许可费用就值得了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM