NuSoap, XML was empty, couldn't parse

1.2k Views Asked by At

First, I have to say that I am totally new to WSDL-based Web Services using NuSOAP. I am trying to return an array of friends list from my soap server. Please find below my code listings as is:

Server:

//File includes omitted

function getFriendList($test = ''){

   $results = array();

   $results[] = array('name' => 'XXXXA1', 'surname' => 'XXXXA2');
   $results[] = array('name' => 'XXXXXB1', 'surname' => 'XXXXB2');
   $results[] = array('name' => 'XXXXXC1', 'surname' => 'XXXXC2');

   return $results;
}

//Create server instance
$server = new soap_server();

//Configure our WSDL
$server->configureWSDL('server', 'urn:server');

//Add our Complex Type  data type since we want to return an array
$server->wsdl->addComplexType(
   'Friend',
   'complexType',
   'struct',
   'all',
   '',
   array(
     'name' => array('name' => 'name', 'type' => 'xsd:string'),
     'surname' => array('name' => 'surname', 'type' => 'xsd:string')
    ) 
  );

//Register our array as a response
$server->wsdl->addComplexType(
  'FriendArray',
  'complexType',
  'array',
  '',
  'SOAP-ENC:Array',
  array(),
  array(
    array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:Friend[]')
   ),
  'tns:Friend'
);

//Register the actual function that retuns the array but in the 
//return n field specify the complex type of array we added onto the wsdl
 $server->register('getFriendList',
   array('test' => 'xsd:string'),
   array('return' => 'tns:FriendArray'),
   'urn:server',
   'urn:server#getFriendList',
   'document',
   'encoded',
   'Fetch a list of friends as an array. If you\'re not here sorry.'  
  );

//Serve the service
$server->service($HTTP_RAW_POST_DATA = (!isset($HTTP_RAW_POST_DATA)) ? $HTTP_RAW_POST_DATA : '');

With this, I hoped that I did everything correctly. I followed the standard procedure to make it work but in vein.

On the client side, I used the soap address url in wsdl and appended it with "?wsdl", so that it give me wsdl file dynamically.

example:

 //Client call
 $client = new nusoap_client("http://soapserver.dev/webroot/part_three/server.php?wsdl", true);

I have also taken labour of adding some whistles and bells on my client object as shown below:

 $client->soap_defencoding = 'UTF-8';
 $client->decode_utf8 = false;

This doesn't seem to help at all. I had experienced an issue earlier since my function accepts no parameter, where my service died because I didnt pass any parameter that speaks of inputs in my $client->call($name, $in, $out). I ended up providing an empty array and I got this error.

Could this be related to the rpc/document parameter types of the register function?

Even using the wsdl file which I saved from my server url, I got the same error.

Can somebody please help me out here? Please!

0

There are 0 best solutions below