由于某些奇怪的原因,我必须使用无法通过WSDL调用的Web服务。
示例XML请求必须是这样的 -
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://tempuri.org/check_Ref_No</Action>
<h:ServiceAuthHeader xmlns="http://tempuri.org/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:h="http://tempuri.org/">
<Username>theusername</Username>
<Password>thepassword</Password>
</h:ServiceAuthHeader>
</s:Header>
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<check_Ref_No xmlns="http://tempuri.org/">
<refno>123456789</refno>
<PRDFRM>0001-01-01T00:00:00</PRDFRM>
<PRDTO>2013-12-18T16:19:00</PRDTO>
<covers />
<err>0</err>
</check_Ref_No>
</s:Body>
</s:Envelope>
我无法理解的是
<Action s:mustUnderstand="1">
到目前为止我做了什么 -
//Loading NuSoap Library
require 'nusoap/nusoap.php';
$client = new nusoap_client($ServiceURL, FALSE);
$client->setUseCurl(false);
$client->soap_defencoding = 'utf-8';
// Setting username and password provided by Walid
$client->setCredentials("theusername","thepassword","basic");
//make the call
$result = $client->call('check_Ref_No', array('refno'=>'123456789','PRDFRM'=>'0001-01-01T00:00:00','PRDTO'=>'2013-12-18T16:19:00','covers'=>'','err'=>0), 'http://tempuri.org/', 'http://tempuri.org/check_Ref_No', false, true);
$err = $client->getError();
if ($err) {
echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
}
// Now checking is the Server Code of the webservice has a fault.
if ($client->fault) {
echo '<h2>Fault</h2><pre>';
print_r($result);
echo '</pre>';
} else {
// echo the actual raw webservice XML data sent
echo htmlspecialchars($client->request, ENT_QUOTES)
// echo the actual raw webservice XML data received.
echo htmlspecialchars($client->response, ENT_QUOTES)
}
...这导致 - 在连接和接收响应方面取得了圆满成功,但却出现了错误 - 服务器无法理解Soap Header。有人有解决方案吗?
P.S使用Nusoap不是强制性的 - 我可以转移到其他任何东西,甚至是PHP的原生SoapClient,我只需要帮助理解如何设置标头以形成请求。