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条)

报告相同问题?

悬赏问题

  • ¥15 蓝桥oj3931,请问我错在哪里
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染