How the nusoap return array?

Sonia picture Sonia · Jan 23, 2011 · Viewed 24.2k times · Source

I write server.php as below:

require_once("lib/nusoap.php");
require_once("connect.php");

$server = new soap_server;

$server->configureWSDL('server', 'urn:RM');

$server->wsdl->addComplexType(
    'game',
    'complexType',
    'struct',
    'all',
    '',
    array(
     'eventId'=>array('name'=>'eventId','type'=>'xsd:int'),
     'eventName'=>array('name'=>'eventName','type'=>'xsd:string'))
    );

$server->register('gamelist',
    array('id'=>'xsd:int'),
    array('return'=>'tns:game'),
    'urn:RM',
    'urn:RM#gamelist',
    'rpc',
    'encoded',
    'Get Games Info');

function gamelist($id){
 $query="select eventId, eventName from jos_games where parentId='$id'";
 $rs=mysql_query($query);

 $game=array();
 while($row=mysql_fetch_assoc($rs)){
  $game[]= $row;
 }
 //print_r($game);
 return $game;
}


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

client.php as below:

require_once("lib/nusoap.php");

$client =  new nusoap_client('http://sonia.ecisoft.com/soap/server.php');


if($err=$client->getError()){
 echo 'Error:'.$err;
}

$id=1;
$return = $client->call('gamelist', array('id'=>$id));

print_r($return);

I can't get return from client.php. I want to list rows of eventId, eventName. Please help me, thank you.

Answer

Xites picture Xites · Apr 18, 2011

I think the PHP type should be "array". Changing the following, should work.

$server->wsdl->addComplexType(
'game',
'complexType',
'array',
'all',
'',
array(
 'eventId'=>array('name'=>'eventId','type'=>'xsd:int'),
 'eventName'=>array('name'=>'eventName','type'=>'xsd:string'))
);

The return value of function gamelist should be like this:

return array("game" => $game);