使用soap标头NuSoap PHP webservice

时间:2011-10-09 18:59:43

标签: php service web nusoap

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

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

谢谢你, MK

2 个答案:

答案 0 :(得分: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>');

答案 1 :(得分:0)

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

<?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);
}

这样做有明显更好的编码实践,但你明白了。对于requestHeader s 属性, whatchout 也是如此,因为它包含HTTP标头而不是SOAP标头,请记住:请求没有尾随's'的请求主页是你的人。

希望有所帮助