21,886
社区成员
发帖
与我相关
我的任务
分享
考虑到安全因素,因此需要WS的客户端在调用服务的时候,请求头需要包含一个验证信息,否则服务将不可访问。
实现方式为注册一个CallbackHandler,进行identifier的验证。
$xml = '
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken>
<wsse:Username>admin</wsse:Username>
<wsse:Password>PasswordText</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>';
$s = new SoapHeader('http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd', 'CallbackHandler', new SoapVar($xml, XSD_ANYXML), TRUE);
$client = new SoapClient($wsdl);
$client->__setSoapHeaders(array($s));
print_r($client);
$client = new SoapClient($url);
$soap_header = New SoapHeader($url, 'CallbackHandler', 'wsAdmin',FALSE, SOAP_ACTOR_NEXT);
$client->__setSoapHeaders(array($soap_header));
$info = $client->__soapCall('getClassStudent', array('userId' => 1));print_r($info);
运行后,每次都报错
SoapFault exception: [ns1:InvalidSecurity] An error was discovered processing the header in /var/www/html/Exam/Lib/Action/Home/IndexAction.class.php:264 Stack trace: #0