Search code examples
phpxmlsoapnusoap

Nusoap, return array of data as XML in web service


I have a PHP soap server (Using nuSoap), and a Java client (using Axis2). Which works pretty good, until it doesn't.

The gist of what I'm trying to do is send a code to the service, and return a XML list of file names.

<filename>20120413.zip</filename>

Here's the SSCE

<?
require_once('nusoap/lib/nusoap.php'); 
$server = new soap_server();
$server->configureWSDL('Download Database Backup', 'urn:downloadDatabase');

$server->register('getBackupFileNames',                                  // method
        array('herdCode' => 'xsd:string'), // input parameters
        array('fileList' => 'xsd:string'),                           // output parameters
        'urn:uploadDatabase',                                               // namespace
        'urn:uploadDatabase#uploadDatabase',                                       // soapaction
        'rpc',                                                       // style
        'encoded',                                                   // use
        'uploadDatabase'                                          // documentation
    );

 function getBackupFileNames($herdCode)
    {
    $location = "/home/rhythms/backups/" . $herdCode;
    $fileList = scandir($location);
    return $fileList;
    }//end function

$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
?>

In a pinch, I know I could do a foreach and manually create the XML as a string. However it gets XMLEncoded then. Is there a better way? I would like to publish it by default in the WSDL. I've also tried the complexType but I had trouble handling that on the Axis2 side.

Thank you!


Solution

  • This isn't a direct answer. What I've come to is you can send a SOAP array using the SOAP-ARRAY complex data type. But it's not a very good method. Instead I'm going to investigate the native SOAP implementation that PHP provides.

    Axis2 doesn't handle the SOAP-ARRAY complex datatype well, so I think it will be easier to adjust my implementation to PHP's native types.

    This is left as a footnote so hopefully someone else won't fall down the same well I did as I was trying to find a good SOAP implementation.