我想在文件中写入 System.ServiceModel.Channels.Message 类型的请求的内容,即使由于 XML 异常而无法读取它。
例如:我调用request.CreateBufferedCopy(int.MaxValue);
where request 是我收到的 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 不可序列化。
这是我测试的请求,我接受了一个有效的肥皂请求并在末尾删除了一个“>” </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>
但我想记录我收到的任何东西,所以我的例子并不重要。