I am using a custom endpoint behavior extension to intercept messages as they are received by my WCF service endpoint, using IDispatchMessageInspector. I retrieve the message content like this:
public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext)
{
MessageBuffer messageBuffer = request.CreateBufferedCopy(Int32.MaxValue);
Message message = messageBuffer.CreateMessage();
using (MemoryStream stream = new MemoryStream())
{
using (XmlWriter writer = XmlWriter.Create(stream))
{
message.WriteMessage(writer);
writer.Flush();
stream.Position = 0;
}
}
}
I need to obtain the XML message exactly as it is sent by the client, but the XML that is written to the stream seems to be modified by WCF (or the XmlWriter?). My main problem is that it has modified closing tags: <id />
becomes <id></id>
everywhere in the XML message. Is there a way to write the message content as it was received by the endpoint without it being modified (or at least without changing the way the tags are closed?