Save and play WCF messages

I want to store WCF messages in some store and read them later to play them again.

Several pieces of code are attached:
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 ();
}
}
}

the problem is that before storing the message, Message.ToString () returns the message string as it would like, the whole message, but after reading it, ToString () shows the body as "... stream" .. "and what it is.

please advise
Thanks a lot :-)

Note that in "WriteMessage" only the body is read and written when the message is wrapped in another message.

+1


source to share


1 answer


Have a look at Charles , you can easily save the session and then replay it again or even edit individual requests and change the hostname etc. We use it to create test sessions, save them, and then re-launch the bot sessions to create a payload test.



The only downside is that the evaluation version only runs for 30 minutes, but hey, if you use it all the time, then it costs $ 50 for the full license price.

+1


source







All Articles