使用soap标头NuSoap PHP webservice

问题描述 投票:1回答:2

我想知道如何使用NuSoap库在soap Web服务服务器中实现soap header身份验证。

我见过很多关于NuSoap Client的例子,但是想在服务器上实现它。

谢谢,mk

php service web nusoap
2个回答
0
投票
    $client->setHeaders('<wsse:Security S:mustUnderstand="1">
            <wsu:Timestamp xmlns:ns15="http://schemas.xmlsoap.org/ws/2006/02/addressingidentity" xmlns:ns14="http://docs.oasis-open.org/ws-sx/ws-secureconversation/200512" xmlns:ns13="http://www.w3.org/2003/05/soap-envelope" wsu:Id="_1">
                <wsu:Created>createdDate</wsu:Created>
                <wsu:Expires>expireDate</wsu:Expires>
            </wsu:Timestamp>
            <wsse:UsernameToken xmlns:ns15="http://schemas.xmlsoap.org/ws/2006/02/addressingidentity" xmlns:ns14="http://docs.oasis-open.org/ws-sx/ws-secureconversation/200512" xmlns:ns13="http://www.w3.org/2003/05/soap-envelope" wsu:Id="uuid_25007e25-6a0a-4a0c-9c3e-0d332f262cdc">
                <wsse:Username>username</wsse:Username>
                <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">password</wsse:Password>
            </wsse:UsernameToken>
        </wsse:Security>');

0
投票

soapserver对象将soap标头保存为'requestHeader'属性下的关联数组,因此如果您能找到从函数中获取服务器实例的方法,则可以获取soapHeader。

<?php
require_once './nusoap/nusoap.php';

//Declare the server as a global, for brevity
global $server;

//Instantiate, configure and run as usual
$server = new nusoap_server();
$server->configureWSDL("namespace...", "...");
$server->register("myHandler");
$server->service(isset($GLOBALS['HTTP_RAW_POST_DATA']) ? $GLOBALS['HTTP_RAW_POST_DATA'] : '');

//My handling function:
function myHandler() {
    //Get your server instance:
    global $server;

    //Abra Kadabra alakazam! your soap header :D
    var_dump($server->requestHeader);
}

这样做有明显更好的编码实践,但你明白了。还有什么对于requestHeaders属性,因为它保存HTTP头而不是SOAP Header,请记住:requestHeader没有尾随's'是你的家伙。

希望能帮助到你

© www.soinside.com 2019 - 2024. All rights reserved.