到目前为止,我还没能通过PHP SoapClient成功地将参数传递给请求。
<?php
class MockSoapClient extends \SoapClient
{
public function __doRequest($request, $location, $action, $version, $one_way = 0)
{
echo $request.PHP_EOL;
return '';
}
}
$client = new MockSoapClient(
'http://www.saiasecure.com/webservice/shipment/soap.asmx?wsdl',
[
'trace' => 1,
'soap_version' => SOAP_1_1,
]
);
$client->__soapCall(
'GetByProNumber',
[
'parameters' => [
'UserID' => 'username',
'Password' => 'password',
'TestMode' => 'Y',
'ProNumber' => '123',
]
]
);
运行:php test.php | xmllint -format -
获得输出:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.SaiaSecure.com/WebService/Shipment">
<SOAP-ENV:Body>
<ns1:GetByProNumber/>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
期望输出在GetByProNumber元素中包含某种形式的参数。
PHP版本:7.0.30(Ubuntu 16.04)
有一个“没有错误”的报告非常模仿这个问题,但是我无法深入了解要改变什么以使其发挥作用。 https://bugs.php.net/bug.php?id=33366
任何人都有任何见解或提示吗?
答案 0 :(得分:1)
我刚检查了你的wsdl,看来正确的参数数组应该是这样的:
[
'parameters' => [
'request' => [
'UserID' => 'username',
'Password' => 'password',
'TestMode' => 'Y',
'ProNumber' => '123',
]
]
]
然后输出将是这样的:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.SaiaSecure.com/WebService/Shipment"><SOAP-ENV:Body><ns1:GetByProNumber><ns1:request><ns1:UserID>username</ns1:UserID><ns1:Password>password</ns1:Password><ns1:TestMode>Y</ns1:TestMode><ns1:ProNumber>123</ns1:ProNumber></ns1:request></ns1:GetByProNumber></SOAP-ENV:Body></SOAP-ENV:Envelope>