存储和重播WCF消息 [英] Store And Replay WCF Messages

查看:84
本文介绍了存储和重播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 .. .就是这样.

请谨慎
非常感谢:-)

请注意:在"WriteMessage"中,由于将消息包装在另一条消息中,因此只能读取和写入正文.

解决方案

看看查尔斯,您可以轻松地存储会话,然后再次播放它,甚至可以编辑单个请求并更改主机名等.我们使用它来生成测试会话,保存它们,然后使用漫游器重放会话以生成有用的负载测试.

唯一的缺点是评估版只能使用30分钟,但是,嘿,如果您一直使用它,那么50美元的完整许可费用就值得了.

I want to store WCF messages in some storage and read them later on in order to "replay" them again.

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.

please advaice
Many thanks :-)

Please note: at the "WriteMessage" only the body is read and written as the message is wrapped in another message.

解决方案

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.

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.

这篇关于存储和重播WCF消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆