开发者

How the nusoap return array?

开发者 https://www.devze.com 2023-02-06 01:29 出处:网络
I write server.php as below: require_once(\"lib/nusoap.php\"); require_once(\"connect.php\"); $server = new soap_server;

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="selec开发者_运维知识库t 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.


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);


Add Complex type of list Array

$soap->wsdl->addComplexType(
 'ListArray',
 'complexType',
 'array',
 '',
 'SOAP-ENC:Array',
  array(),
  array(
    array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'xsd:string[]')
  ),
  'xsd:string'

);

Register Function

        $soap->register(
"YourAPIName",
array( ),
array('return' => 'tns:ListArray'),
API_NAMESPACE,
false, false, false,

)

0

精彩评论

暂无评论...
验证码 换一张
取 消