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());
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?