How to get text from channels.message when there's a XmlException?

526 Views Asked by At

I want to write in a file the content of a request of type System.ServiceModel.Channels.Message even when I can't read it because of an exception with the XML.

Ex : I call request.CreateBufferedCopy(int.MaxValue); where request is my Channels.Message I receive and it return the following error :

System.Xml.XmlException: The token '>' was expected but found 'a'. Line 80, position 19.
   at System.Xml.XmlExceptionHelper.ThrowXmlException(XmlDictionaryReader reader, String res, String arg1, String arg2, String arg3)
   at System.Xml.XmlExceptionHelper.ThrowTokenExpected(XmlDictionaryReader reader, String expected, Char found)
   at System.Xml.XmlUTF8TextReader.ReadEndElement()
   at System.Xml.XmlUTF8TextReader.Read()
   at System.Xml.XmlBinaryWriter.WriteTextNode(XmlDictionaryReader reader, Boolean attribute)
   at System.Xml.XmlDictionaryWriter.WriteNode(XmlDictionaryReader reader, Boolean defattr)
   at System.ServiceModel.Channels.ReceivedMessage.OnWriteBodyContents(XmlDictionaryWriter writer)
   at System.ServiceModel.Channels.Message.OnWriteMessage(XmlDictionaryWriter writer)
   at System.ServiceModel.Channels.Message.OnCreateBufferedCopy(Int32 maxBufferSize, XmlDictionaryReaderQuotas quotas)
   at System.ServiceModel.Channels.Message.CreateBufferedCopy(Int32 maxBufferSize)

I want to be able to write the content of request in a file so I can see what the actual problem is. (this is a simple example, but there can be other reasons I want to write this file)

I tried converting my request in a byte array using BinaryFormatter, but Channels.Message is not serializable.

Here's the request I tested with, I took a valid soap request and removed a '>' at the end of </controlActEvent :

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
    <Security s:actor="IntervenantEmetteur" xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
        <Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
            <SignatureValue>ofb/GTvjhT5Jqyl5x2D</SignatureValue>
        </Signature>
    </Security>
</s:Header>
<s:Body wsu:Id="_0" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
    <PRPA_IN1 xmlns="urn:hl7-org:v3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:hl7-org:v3 ../PRP1.xsd"
ITSVersion="XML_1.0">
        <id root="BB7321A1-33" />
        <creationTime value="20070" />
        <receiver typeCode="RCV">
            <device classCode="DEV" determinerCode="INSTANCE">
                <id root="2.16.124" extension="RU" use="BUS" />
            </device>
        </receiver>
        <sender typeCode="SND">
            <device classCode="DEV" determinerCode="INSTANCE">
                <id root="2.16.124.10." extension="APPTEST" />
                <name>App</name>
            </device>
        </sender>
        <controlActEvent classCode="CACT" moodCode="EVN">
            <responsibleParty typeCode="RESP" contextControlCode="AP">
                <assignedEntity classCode="ASSIGNED">
                </assignedEntity>
            </responsibleParty>
            <author typeCode="AUT" contextControlCode="AP">
            </author>
            <location typeCode="LOC" contextControlCode="AP">
            </location>
            <queryByParameter>
                <queryId root="BB7321A1-3" />
                <parameterList>
                </parameterList>
            </queryByParameter>
        </controlActEvent
    </PRPA_IN1>
</s:Body>

But I want to log anything that I receive, so my example doesn't really matter.

0

There are 0 best solutions below