我遇到了越来越Java服务客户端与WCF服务成功通信的可气的问题。我克服了许多障碍,我认为这是我的最后一个。这个问题归结到Java轴+ 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>

此响应使用简单的一字符的命名空间前缀对于大多数的东西,如“S”为SOAP信封,“A”为WS寻址,“O”为“的WS-Security”等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元素的别名,如“WSA”为WS-Addressing和“WSSE”的WS-Security的扩展。因为无论这些命名空间中的存在于实际响应XML,引发异常。

我想知道是否有任何简单的方法来从一组命名空间的转换XML文档以使用C#,.NET和System.Xml命名空间的另一组。我戳周围的XmlNamespaceManager了一点,但它似乎并没有完全支持我需要什么......或者至少,我一直无法找到任何真正有用的例子,我不能完全肯定它是如何工作的。我试图避免写一些重型工艺手工处理此我自己,因为我不希望大大影响我们的服务的性能时,由Java轴/ WSS4J客户端调用。

有帮助吗?

解决方案

这个特定问题似乎从旧和马车版本WSS4J的干。新版本似乎不存在这个问题,它不再是一个问题。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top