[英]Convert XML namespace prefixes with C#?
讓Java服務客戶端與WCF服務成功通信時,我遇到了一個令人煩惱的問題。 我克服了許多障礙,我相信這是我的最后一個障礙。 問題歸結為Java Axis + WSS4J似乎如何處理xml名稱空間。 Java平台似乎對XML命名空間前綴的期望非常嚴格,因此不了解WCF答復消息。
概括地說,我的問題如下。 我的WCF服務具有類似於以下內容的xml響應:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<s:Header>
<a:Action s:mustUnderstand="1" u:Id="_3">http://tempuri.org/IProcessor/DoProcessingResponse</a:Action>
<h:CorrelationID xmlns:h="http://tempuri.org/">1234</h:CorrelationID>
<a:RelatesTo u:Id="_4">uuid:40f800a0-9613-4f4a-96c5-b9fd98085deb</a:RelatesTo>
<o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<!-- WS-Security header stuff -->
</o:Security>
</s:Header>
<s:Body u:Id="_1">
<e:EncryptedData Id="_2" Type="http://www.w3.org/2001/04/xmlenc#Content" xmlns:e="http://www.w3.org/2001/04/xmlenc#">
<e:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes128-cbc"/>
<e:CipherData>
<e:CipherValue>NfA6XunmyLlT2ucA+5QneoawHm+imcaCltDAJC1mRZOSxoB6YGpDLY1FyVykPbPGDoFGUESLsmvvbD62sNnRrgE+AuKPo+1CD3DF4LfurRcEv9A50ba9V+ViqlrhydhK</e:CipherValue>
</e:CipherData>
</e:EncryptedData>
</s:Body>
</s:Envelope>
對於大多數情況,此響應使用簡單的一個字符的名稱空間前綴,例如SOAP Envelope的“ s”,WS-Addressing的“ a”,WS-Security的“ o”等。似乎是Java客戶端,即WSS4J預期以下情況:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsa="http://www.w3.org/2005/08/addressing" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<soap:Header>
<wsa:Action soap:mustUnderstand="1" wsu:Id="_3">http://tempuri.org/IProcessor/DoProcessingResponse</wsa:Action>
<h:CorrelationID xmlns:h="http://tempuri.org/">1234</h:CorrelationID>
<wsa:RelatesTo wsu:Id="_4">uuid:40f800a0-9613-4f4a-96c5-b9fd98085deb</a:RelatesTo>
<wsse:Security soap:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<!-- WS-Security header stuff -->
</wsse:Security>
</soap:Header>
<soap:Body u:Id="_1">
<xenc:EncryptedData Id="_2" Type="http://www.w3.org/2001/04/xmlenc#Content" xmlns:xenc="http://www.w3.org/2001/04/xmlenc#">
<xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes128-cbc"/>
<xenc:CipherData>
<xenc:CipherValue>NfA6XunmyLlT2ucA+5QneoawHm+imcaCltDAJC1mRZOSxoB6YGpDLY1FyVykPbPGDoFGUESLsmvvbD62sNnRrgE+AuKPo+1CD3DF4LfurRcEv9A50ba9V+ViqlrhydhK</xenc:CipherValue>
</xenc:CipherData>
</xenc:EncryptedData>
</soap:Body>
</soap:Envelope>
收到我的響應消息后,Java客戶端和WSS4J似乎想通過它們自己的內部xml別名來查找元素,例如WS-Addressing的“ wsa”和WS-Security Extensions的“ wsse”。 由於這些名稱空間都不存在於實際的響應xml中,因此會引發異常。
我想知道是否有任何簡單的方法可以使用C#、. NET和System.Xml命名空間將xml文檔從一組命名空間轉換為另一組命名空間。 我已經與XmlNamespaceManager進行了一些討論,但是它似乎並不能完全支持我所需要的東西……或者至少,我無法找到任何真正有用的示例,並且不確定其工作原理。 我試圖避免不得不自己編寫一些繁重的流程來手動處理此問題,因為當Java Axis / WSS4J客戶端調用我不想極大地影響我們的服務性能時,我會這樣做。
這個特殊問題似乎源於WSS4J的舊版本。 較新的版本似乎沒有此問題,並且不再是問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.