2010-03-28 79 views
0

我遇到了让Java服务客户端与WCF服务成功通信的恼人问题。我克服了很多障碍,我相信这是我的最后一个障碍。问题归结为Java Axis + WSS4J如何处理xml命名空间。 Java平台对xml命名空间前缀的期望看起来非常严格,因此不理解WCF回复消息。用C#转换XML名称空间前缀?

我的问题简而言之如下。我也有类似的从我的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-Addressing的,“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别名创建元素,例如用于WS-Addressing的'wsa'和用于WS-Security Extensions的'wsse'。由于这两个名称空间都不存在于实际响应xml中,因此会引发异常。

我想知道是否有任何简单的方法来将xml文档从一组命名空间转换为使用C#,.NET和System.Xml命名空间的另一组命名空间。我用XmlNamespaceManager稍微探讨了一下,但它似乎并没有完全支持我所需要的......或者至少,我一直无法找到任何真正有用的示例,并且我不完全确定它是如何工作的。我试图避免编写一些繁重的过程来手动处理这个问题,因为我不想在Java Axis/WSS4J客户端调用时大幅影响我们的服务性能。

回答

0

这个特殊的问题似乎源于WSS4J的老式和buggy版本。新版本似乎没有这个问题,这不再是一个问题。