带肥皂标题的NuSoap PHP webservice
问题描述:
我想知道如何在使用NuSoap库的soap web服务服务器中实现soap标头认证。带肥皂标题的NuSoap PHP webservice
我已经看到很多关于NuSoap客户端的例子,但是想要在服务器上实现它。
谢谢 MK
答
$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>');
答
的SoapServer的对象持有的肥皂头为“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);
}
这样做显然有更好的编码实践,但你有这个想法。还有whatchout请求头部s属性,因为它拥有HTTP标头而不是SOAP标头,请记住:requestHeader没有尾随's'就是你的家伙。
希望它有帮助