0
我有一個具有以下簽名有點WCF服務:在WCF反序列化的XML元素與XML聲明
string ProcessMessage(XmlElement xmlSource);
當我沒有XML聲明的請求,web服務工作正常,但只要xml聲明被添加,我得到一個崩潰。
的作品
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
<soapenv:Header/>
<soapenv:Body>
<tem:ProcessMessage>
<tem:xmlSource>
<clipped>elements here</clipped>
</tem:xmlSource>
</tem:ProcessMessage>
</soapenv:Body>
</soapenv:Envelope>
請求不起作用
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
<soapenv:Header/>
<soapenv:Body>
<tem:ProcessMessage>
<tem:xmlSource>
<?xml version="1.0" encoding="UTF-8"?>
<clipped>elements here</clipped>
</tem:xmlSource>
</tem:ProcessMessage>
</soapenv:Body>
</soapenv:Envelope>
和碰撞吸能請求:
<Message>No characters can appear before the XML declaration. Line 7, position 14.</Message>
<StackTrace>at System.Xml.XmlExceptionHelper.ThrowXmlException(XmlDictionaryReader reader, String res, String arg1, String arg2, String arg3)
at System.Xml.XmlUTF8TextReader.ReadDeclaration()
at System.Xml.XmlUTF8TextReader.Read()
at System.Xml.XmlBaseReader.MoveToContent()
at System.Xml.Serialization.XmlSerializationReader.ReadXmlNode(Boolean wrapped)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderINBUWProcessingService.Read1_ProcessMessage()
at Microsoft.Xml.Serialization.GeneratedAssembly.ArrayOfObjectSerializer.Deserialize(XmlSerializationReader reader)
at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)</StackTrace>
<Type>System.Xml.XmlException</Type>
</InnerException>
<Message>There is an error in XML document (7, 14).</Message>
<StackTrace>at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle)
at System.ServiceModel.Dispatcher.XmlSerializerOperationFormatter.DeserializeBody(XmlDictionaryReader reader, MessageVersion version, XmlSerializer serializer, MessagePartDescription returnPart, MessagePartDescriptionCollection bodyParts, Object[] parameters, Boolean isRequest)</StackTrace>
<Type>System.InvalidOperationException</Type>
我認爲正在發生的是WCF服務正在將整個soap信封讀取爲一個xml文檔,然後當它遇到xml聲明時(對於段落計量器xmlSource
),並將其解釋爲整個肥皂包的xml文檔。這是崩潰的地方,並說xml聲明必須是文檔的第一部分。
有沒有辦法解決這個問題或從請求中去除XML聲明之前,它擊中了Web服務?
你用什麼作爲WCF服務的客戶端?你是從頭開始構建自己的請求還是使用Web引用或WCF ChannelFactory> –
這些請求是從一個JAVA應用程序進來的,我不幸無法控制。 –
如果您確實無法讓客戶端發送有效的XML,那麼我認爲您可能需要創建一個接受內容的非WCF處理程序,清除它並將其轉發給WCF服務。我查看了[本文檔](http://msdn.microsoft.com/en-us/magazine/cc163302.aspx#S5)中描述的各種攔截點,但它們似乎都是在請求已經完成之後解析爲SOAP,如果它不是有效的XML,將會失敗。 –