douboshan1466 2013-12-18 13:36
浏览 29
已采纳

PHP从soap服务获取数据

I need to get data from http://ws.jrtwebservices.com/jrtlowfaresearch/jrtlfs.asmx, this service need credential information.such as ID, userid and system value. I put these information into one string:

$xml_post_string = "<POS><Source> <RequestorID Type='21' ID='xxx'/> </Source> <TPA_Extensions> <Provider><System>xxx</System> <Userid>xxx</Userid>  </Provider></TPA_Extensions></POS>"

And i also defined SoapClient:

$client = new SoapClient(null, array('uri' => "http://ws.jrtwebservices.com",
                                 'location => "http://ws.jrtwebservices.com/jrtlowfaresearch/jrtlfs.asmx") );

I call soapCall as:

$response = $client->__soapCall('do_LowfareSearch',array($xml_post_string),array('soapaction' => 'http://jrtechnologies.com/do_LowfareSearch')); 

Does anybody know why i get empty response?

Thanks very much!

  • 写回答

1条回答 默认 最新

  • douxue7196 2013-12-24 07:08
    关注

    Using your code, the request looks like this:

    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xm...">
        <SOAP-ENV:Body>
            <ns1:do_LowfareSearch>
                <param0 xsi:type="xsd:string">
                    "<POS><Source> <RequestorID Type='21' ID='xxx'/> </Source> <TPA_Extensions> <Provider <System>xxx</System> <Userid>xxx</Userid>  </Provider></TPA_Extensions></POS>"
                </param0>
            </ns1:do_LowfareSearch>
        </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>
    

    The client used the method you passed but could not structure the parameters the way you gave them. All of your parameters are just in " " inside of <param0>.

    (Also, you are missing a ' after location. 'location => "http:...)

    When you make your SOAP client you want to set the WSDL, it will do all the XML formatting for you.

    The WSDL should have the location in it so you do not need to worry about that.

    I like to use a WSDL validator to test out the methods and see their parameters.

    You should structure the information you want to pass as arrays or a classes and let the SOAP client and WSDL convert it into the XML you need.

    So something like this is what you are looking for:

    <?php
    //SOAP Client
    $wsdl = "http://ws.jrtwebservices.com/jrtlowfaresearch/jrtlfs.asmx?WSDL"; 
    $client = new SoapClient($wsdl, array(  'soap_version' => SOAP_1_1,
                                            'trace' => true, //to debug
                                            )); 
    try {
        $args = array(
            'companyname'=> 'xxx',
            'name'=> 'xxx',
            'system'=> 'xxx',
            'userid'=> 'xxx',
            'password'=> 'xxx',
            'conversationid'=>'xxx',
            'entry'=> 'xxx',
            );
        $result = $client->__soapCall('do_LowfareSearch', $args);
        return $result;
    } catch (SoapFault $e) {
        echo "Error: {$e}";
    }
    //to debug the xml sent to the service
    echo($client->__getLastRequest());
    //to view the xml sent back
    echo($client->__getLastResponse());
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥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美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号