Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

How can I return ONLY xml from nusoap call?

Help
Paul Maine
2010-05-14
2013-06-06
  • Paul Maine
    Paul Maine
    2010-05-14

    I am writing an application that is using a soap call to retrieve a large amount of data.

    After many hours of working with the soap library that is included with PHP, I discovered the standard SOAP library for PHP in PHP version 5.2.5 does not handle a web response with a Transfer-Encoding: Chunk. A fatal exception is thrown. I next upgraded to PHP 5.3.2 that is supposed to handle Transfer-Encoding: Chunk.

    I next decided to see if NuSOAP could handle the Transfer-Encoding: Chunk. I was pleasantly surprised to find that it handled Chunked just fine!

    Here is my last problem. I only want to retrieve the xml document from the webservice. When I use the following code I get returned and object and an xml document. How can I just retrieve the xml document?

    Here is my code:

    require_once 'lib/nusoap.php';

    $soapclient = new soapclient("https://www.mydomain.com/MY_API.asmx?WSDL", "wsdl");

    $params = array(
        'strUID'     => 'myUsername',
        'strPWD'    => 'myPassword',
        'Query' =>'select * from mytable'
         );   
        // invoke the method on the server
        // Proxy
        $proxy = $soapclient->getProxy();
        $result = $proxy->getRecords($params); // invoke the method

    // Check for a fault
    if ($soapclient->fault)
    {
    echo '<h2>Fault (Expect - AUTHENTIFICATION)</h2><pre>';
    print_r($result);
    echo '</pre>';
    } else
    {
    // Check for errors
    $err = $soapclient->getError();
    if ($err) {
    // Display the error
    echo '<h2>Error</h2><pre>' . $err . '</pre>';
    } else {
    // Display the result
    echo '<h2>Result</h2><pre>';
    print_r($result);
    echo '</pre>';
    }
    }

    The print_r($result) is showing me that I am retreiving the data from the webservice properly. I just need to get the response in xml rather than an array.

    Thank you in advance for your assistance!

     
  • Paul Maine
    Paul Maine
    2010-05-14

    PHP 5.3.2 soapclient did not properly handle Transfer-Encoding: Chunk either.

     
  • Paul Maine
    Paul Maine
    2010-05-15

    I resolved the question. The following code works fine and provides the xml:

    require_once 'lib/nusoap.php';

    $soapclient = new soapclient("https://www.noway.com?WSDL", "wsdl");

    $params = array(
        'strUID'     => 'myUsername',
        'strPWD'    => 'myPassword',
        'Query' =>'select * FROM myTable');
        $result = $soapclient->call('GetRecords',$params);
    // Check for a fault
    if ($soapclient->fault) {
    echo '<h2>Fault (Expect - AUTHENTIFICATION)</h2><pre>';
    print_r($result);
    echo '</pre>';
    } else {
    // Check for errors
    $err = $soapclient->getError();
    if ($err)
    {
    // Display the error
    echo '<h2>Error</h2><pre>' . $err . '</pre>';
    } else
    {
    // Display the result
    echo '<h2>Result</h2><pre>';
    print_r($result);
    echo '</pre>';
    }
    }

    echo $soapclient->responseData;// This variable contains the xml