我有一个有效的XML请求体,我试图通过PHP发送到SOAP服务器:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="urn:servicewsdl" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<mns:getQuote xmlns:mns="urn:getquoteswsdl" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<authorisation xsi:type="tns:Authorisation">
<username xsi:type="xsd:string">****</username>
<password xsi:type="xsd:string">****</password>
</authorisation>
<symbol xsi:type="xsd:string">****</symbol>
</mns:getQuote>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
我尝试将params传递给数组:
$result = $client->getQuote(array('username' => '****', 'password' => '****'), array('symbol' => '****'));
但它给我一个错误:
SOAP-ERROR: Encoding: object has no 'username' property
答案 0 :(得分:2)
您可能需要将用户名/密码数组放在授权内:
$result = $client->getQuote(array('authorisation'=>array('username' => '****', 'password' => '****')), array('symbol' => '****'));
或者,也许你应该发送一个对象:
$params = new stdClass();
$params->authorisation = new stdClass();
$params->authorisation->username = '****';
$params->authorisation->password = '****';
$params->symbol = '****';
$result = $client->getQuote($params);
编辑:从评论开始,最终通过PHP以这种方法访问getQuote:
$auth = new stdClass();
$auth->username = '****';
$auth->password = '****';
$symbol = '****';
$result = $client->getQuote($auth, $symbol);
答案 1 :(得分:1)
我还有很多时间使用PHP和SOAP。我似乎回想起类似的情况,我使用标准的PHP类(新的stdClass())来帮助用params构建对象。这是问题/答案页面。
How can I add Attributes to a PHP SoapVar Object?
我希望它有所帮助。