WCF Endpoint: Message.WriteMessage Modifies End Tags Inside an XML Message

I am using a custom endpoint behavior extension to intercept messages as they are received by my WCF service endpoint using IDispatchMessageInspector. I get the contents of the message as follows:


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 get an XML message exactly the same as it was sent by the client, but the XML that is being written to the stream seems to be changing WCF (or XmlWriter?). My main problem is that it modified the closing tags: <id />it gets <id></id>everywhere in the XML message. Is there a way to write the contents of the message since it was received by the endpoint without modifying it (or at least without changing the way tags are closed?)

+3
2

, . Message.WriteMessage, XML, MessageBuffer.CreateBufferedCopy! , , , CreateBufferedCopy Message.WriteMessage, XML .

, , XML , , WCF , .. WCF MessageEncoders, . , WCF Message , .

, WCF , MessageEncoders. . Microsoft:

!

+1

, , , .

, xml xmlwriter.

, . ToString().

EDIT , WCF XML , xml.

, XML- , WCF .

EDIT 2 , , , . ?

+1

Source: https://habr.com/ru/post/1711816/


All Articles