How to read data from SOAP header in client side

和自甴很熟 提交于 2019-12-13 16:56:07

问题


I have SOAP response which looks like

<soap:Envelope>
    <soap:Header>
        <AuthorizationToken soap:mustUnderstand="1">
            <Token>5c31cca8-8303-4d01-a564-a99569a0963a</Token>
        </AuthorizationToken>
    </soap:Header>
    <soap:Body>
        <AuthenticateResponse>
            <AuthenticateResult>http://www.avectra.com/OnDemand/2005/</AuthenticateResult>
        </AuthenticateResponse>
    </soap:Body>
</soap:Envelope>

and no clue how to read data from the header (get a token value). I'm using SoapClient from PHP5.


回答1:


From http://drupalcode.org/project/netforum.git/blob/refs/heads/master:/xwebSecureOD.class.inc it looks like this should work:

$soapclient->__soapCall($fname, $arguments, null, $this->getAuthHeaders(), $responseHeaders);
$responseHeaders['AuthorizationToken']->Token;

That link has a class that extends PHP's soap object and does some caching and drupal specific things, but you should be able to remove those pieces and be left with a new class that transparently handles the sliding authorization token netFORUM uses.




回答2:


As per the manual:

$soapclient->__soapCall("soapmethod", array(parameters), null, $input_headers, &$output_headers);

$output_headers should then contain the headers from the response message.




回答3:


I got this from JackTheKnife on http://hardforum.com/showthread.php?t=1651481

    $result = $service->getLastResponse();
    $xmlString = preg_replace("/(<\/?)(\w+):([^>]*>)/", "$1$2$3", $result);
    $xml = simplexml_load_string($xmlString);
    $token = $xml->soapHeader[0]->AuthorizationToken[0]->Token;


来源:https://stackoverflow.com/questions/8124861/how-to-read-data-from-soap-header-in-client-side

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!