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?
I have not tested this, but it might be worth a try.
Idea is that the modification to the xml is being done by the xmlwriter.
You could then get the contents of the message by doing a message.ToString().
EDIT Looks like WCF will change the XML on the server or client side if you send it over as xml.
What you could do is to send the xml over as a byte array, that way WCF will not try to change it.
EDIT 2 The custom message encoder that you mentioned, looks like it both encodes and decodes messages. Would it therefore need to run on the client side as well?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With