dougu9895 2016-02-11 14:12
浏览 63
已采纳

PHP SOAP复杂类型

I have a working XML request body, which I'm trying to send via PHP to a SOAP server:

<?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>

I tried passing the params in an array like so:

$result = $client->getQuote(array('username' => '****', 'password' => '****'), array('symbol' => '****'));

but it returns me an error:

SOAP-ERROR: Encoding: object has no 'username' property
  • 写回答

2条回答 默认 最新

  • dongxiegao3071 2016-02-11 14:18
    关注

    you probably need to put the username/password array inside authorisation like:

    $result = $client->getQuote(array('authorisation'=>array('username' => '****', 'password' => '****')), array('symbol' => '****'));
    

    or, maybe you should send it an object instead:

    $params = new stdClass();
    $params->authorisation = new stdClass();
    $params->authorisation->username = '****';
    $params->authorisation->password = '****';
    $params->symbol = '****';
    $result = $client->getQuote($params);
    

    EDIT: From the comments, in the end, getQuote was accessed via PHP in this method:

    $auth = new stdClass();
    $auth->username = '****';
    $auth->password = '****';
    $symbol = '****';
    $result = $client->getQuote($auth, $symbol);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。
  • ¥20 CST怎么把天线放在座椅环境中并仿真
  • ¥15 任务A:大数据平台搭建(容器环境)怎么做呢?