当有XmlException时,如何从channels.message获取文本?

时间:2017-02-13 21:06:30

标签: c# .net xml soap xmlexception

我想在文件中写入System.ServiceModel.Channels.Message类型的请求的内容,即使我因为XML的异常而无法读取它。

例如:我调用request.CreateBufferedCopy(int.MaxValue);请求是我的Channels.Message我收到并返回以下错误:

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)

我希望能够在文件中写入请求的内容,以便我可以看到实际问题是什么。 (这是一个简单的例子,但我想写这个文件还有其他原因)

我尝试使用BinaryFormatter在字节数组中转换我的请求,但Channels.Message不可序列化。

以下是我测试的请求,我接受了有效的肥皂请求并删除了'&gt;'在</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>

但是我想记录我收到的任何内容,所以我的例子并不重要。

0 个答案:

没有答案