2

我需要阅读 SOAP 标头。下面是发送的xml:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://services.com/" xmlns:ns2="http://tech.com/">
<SOAP-ENV:Header>
    <ns2:header id="ref1">
        <session_id>63949bc1878725afd28cc8283ec3252a</session_id>
        <ip_address>127.0.0.1</ip_address>
        <user_agent>Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:19.0) Gecko/20100101 Firefox/19.0</user_agent>
        <last_activity>1362395880</last_activity>
        <user_data></user_data>
        <username>serge</username>
        <logged_in>true</logged_in>
    </ns2:header>
    <ns2:header href="#ref1"/>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
    <ns1:getInvo>
        <id>1</id>
    </ns1:getInvo>
</SOAP-ENV:Body>

我需要阅读包含 session_id 等的 ns2:header 内部...

4

1 回答 1

0

您可以使用以下代码阅读

SOAPMessage soapMessage=  context.getMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
SOAPHeader soapHeader = soapEnvelope.getHeader(); 

我们可以直接在soapheader上应用解析,如下所示

NodeList nodes =soapHeader.getElementsByTagName("param");
于 2013-03-06T10:18:04.643 回答