所以基本上我希望SOAP标头是这样的:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://xfire.super8.com/CrsService" xmlns:ns2="http://www.gzjhotel.com:9999/iPegasus/services/CrsService?wsdl">
<SOAP-ENV:Header>
<AuthenticationToken>
<Username>xxx</Username>
<Password>xxx</Password>
</AuthenticationToken>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:getHotelList>
<ns1:city>GZ</ns1:city>
</ns1:getHotelList>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
但是,现在我有了这个:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://xfire.super8.com/CrsService" xmlns:ns2="http://www.gzjhotel.com:9999/iPegasus/services/CrsService?wsdl">
<SOAP-ENV:Header>
<ns2:AuthenticationToken SOAP-ENV:actor="http://schemas.xmlsoap.org/soap/actor/next">
<Username>xxx</Username>
<Password>xxx</Password>
</ns2:AuthenticationToken>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:getHotelList>
<ns1:city>GZ</ns1:city>
</ns1:getHotelList>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
这是我当前正在使用的php代码:
$headerParam = [
'Username' => $username,
'Password' => $password,
];
$client = new \SoapClient($requestUrl, ['trace' => true]);
$authvalues = new \SoapVar($headerParam, SOAP_ENC_OBJECT);
$header = new \SoapHeader($requestUrl, 'AuthenticationToken', $authvalues,
false, SOAP_ACTOR_NEXT);
$client->__setSoapHeaders($header);
$r = $client->getHotelList(['city' => 'GZ']);
我哪里出错了?我似乎无法正确构造标题。
答案 0 :(得分:0)
我已经通过使用XSD_ANYXML解决了它
$headerParam = "<AuthenticationToken><Username>$username</Username><Password>$password</Password></AuthenticationToken>";
$client = new \SoapClient($requestUrl, ['trace' => true]);
$authvalues = new \SoapVar($headerParam, XSD_ANYXML);
$header = new \SoapHeader($requestUrl, 'AuthenticationToken', $authvalues, false, SOAP_ACTOR_NEXT);
$client->__setSoapHeaders($header);