如何从soap:header获取SessionID?

时间:2022-10-09 11:38:01

I got a soap xml response and I need the SessionID. I tried to use SimpleXml_load_string but got a empty object back. Has anybody any idea how to get the SessionID?

我得到了一个soap xml响应,我需要SessionID。我试图使用SimpleXml_load_string,但得到了一个空对象。有谁知道如何获得SessionID?

This is the xml response:

这是xml响应:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Header>
    <Header xmlns="http://www.twinfield.com/">
        <SessionID>ca363c52-c12f-4988-b06a-e0c41788e254</SessionID>
    </Header>
</soap:Header>
<soap:Body>
    <LogonResponse xmlns="http://www.twinfield.com/">
        <LogonResult>Ok</LogonResult>
        <nextAction>None</nextAction>
        <cluster>https://c3.twinfield.com</cluster>
    </LogonResponse>
</soap:Body>
</soap:Envelope>

2 个解决方案

#1


0  

Try using DOM. This is one way:

尝试使用DOM。这是一种方式:

$s = '<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Header>
    <Header xmlns="http://www.twinfield.com/">
        <SessionID>ca363c52-c12f-4988-b06a-e0c41788e254</SessionID>
    </Header>
</soap:Header>
<soap:Body>
    <LogonResponse xmlns="http://www.twinfield.com/">
        <LogonResult>Ok</LogonResult>
        <nextAction>None</nextAction>
        <cluster>https://c3.twinfield.com</cluster>
    </LogonResponse>
</soap:Body>
</soap:Envelope>';

$doc   = new DOMDocument();
$doc->loadXML( $s );
echo $doc->getElementsByTagName('SessionID')->item(0)->nodeValue;

#2


0  

I found some thing useful here.Read this https://groups.google.com/forum/#!topic/soap4r/-5IwhynDoEU:

我在这里发现了一些有用的内容。阅读https://groups.google.com/forum/#!topic/soap4r/-5IwhynDoEU:

and https://scn.sap.com/thread/3543465

#1


0  

Try using DOM. This is one way:

尝试使用DOM。这是一种方式:

$s = '<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Header>
    <Header xmlns="http://www.twinfield.com/">
        <SessionID>ca363c52-c12f-4988-b06a-e0c41788e254</SessionID>
    </Header>
</soap:Header>
<soap:Body>
    <LogonResponse xmlns="http://www.twinfield.com/">
        <LogonResult>Ok</LogonResult>
        <nextAction>None</nextAction>
        <cluster>https://c3.twinfield.com</cluster>
    </LogonResponse>
</soap:Body>
</soap:Envelope>';

$doc   = new DOMDocument();
$doc->loadXML( $s );
echo $doc->getElementsByTagName('SessionID')->item(0)->nodeValue;

#2


0  

I found some thing useful here.Read this https://groups.google.com/forum/#!topic/soap4r/-5IwhynDoEU:

我在这里发现了一些有用的内容。阅读https://groups.google.com/forum/#!topic/soap4r/-5IwhynDoEU:

and https://scn.sap.com/thread/3543465