我有一个带有WSSE安全头的客户端调用:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header><wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"><wsse:UsernameToken wsu:Id="UsernameToken-7BCCD9337425FBA038149772606059420"><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:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">NONCE</wsse:Nonce><wsu:Created>2017-06-17T19:01:00.594Z</wsu:Created></wsse:UsernameToken></wsse:Security></soapenv:Header>
<soapenv:Body>
<ns:FUNCTION/>
</soapenv:Body>
</soapenv:Envelope>作为SoapServer,我有一个简单的例子:
// the SOAP Server options
$options=array(
'trace' => true
, 'cache_wsdl' => 0
, 'soap_version' => SOAP_1_1
, 'encoding' => 'UTF-8'
);
$wsdl = 'http://localhost/index.php?wsdl';
$server = new \SoapServer($wsdl, $options);
$server->setClass('ServerClass');
$server->handle();
$response = ob_get_clean();
echo $response;一旦属性MustUnderstand = 1,我就从服务器变成例外:头不被理解。
发布于 2017-06-18 13:20:34
解决办法很棘手!我不知道为什么SoapServer用这种方式来处理这个问题,但是下面是解决方案:
class ServerClass {
public function Security($data) {
// ... do nothing
}
public function myFunction(){
// here the body function implementation
}
}我们需要在我们的类中定义一个函数,它使用header标记的名称来处理soap请求,该标签保存着soap:芥末理解属性。该函数不需要以某种方式实现。
就这样!
发布于 2019-05-26 14:07:33
穆塔托斯的问题/答案使我走上了正确的道路。我在班级结构之外工作,所以对我有用的是以下几点:
function Security($data)
{
$username = $data->UsernameToken->Username;
$password = $data->UsernameToken->Password;
//check security credentials here
}
$server = new SoapServer("schema/wsdls/FCI_BookingPullService.wsdl", array('soap_version' => SOAP_1_2));
$server->addFunction("Security");
$server->handle();本质上是定义一个与SOAP头"“(忽略名称空间)同名的函数,然后告诉服务器使用'addFunction‘方法处理标头。
从范围的角度来看,这并不理想,如果这是一个问题,请尝试类方法。
https://stackoverflow.com/questions/44608568
复制相似问题