php nusoap如何返回数组?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4774555/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How the nusoap return array?
提问by Sonia
I write server.php as below:
我写 server.php 如下:
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:
client.php 如下:
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.
我无法从 client.php 获得回报。我想列出 eventId、eventName 的行。请帮帮我,谢谢。
回答by Xites
I think the PHP type should be "array". Changing the following, should work.
我认为 PHP 类型应该是“数组”。改变以下,应该工作。
$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:
函数gamelist的返回值应该是这样的:
return array("game" => $game);
回答by Pir Abdul
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,
)
)