2011-07-12 11 views
1

私はWebサービスを初めて使っています。私は、クエリ(複数のテーブルからデータを取得)し、その結果は、MySQLから返さ応じて動的配列を返すことができますPHP nusoapサーバ側の汎用関数を書きたいphp nusoap戻り配列

...

ここでは、サーバーのコードがあります...

require_once ('../lib/nusoap.php'); 
$server = new soap_server; 
$server->register('getallbook'); 
function getallbook() 
{ 
$conn = mysql_connect('localhost','root',''); 
mysql_select_db('apexinventry', $conn); 

$sql = "SELECT * FROM users"; 
$q = mysql_query($sql); 
while($r = mysql_fetch_array($q)){ 
    $items[] = array('cd'=>$r['id'],'title'=>$r['userid'],'author'=>$r['password'],'publisher'=>$r['groupid']); 
} 
return $items; 

} 

$server->service($HTTP_RAW_POST_DATA); 

、ここでは

require_once ('../lib/nusoap.php'); 

$client = new soapclient('http://127.0.0.1/test/server/index.php'); 

$response = $client->call('getallbook'); 

if($client->fault) 
{ 
echo "FAULT: <p>Code: (".$client->faultcode.")</p>"; 
echo "String: ".$client->faultstring; 
} 
else 
{ 
$r = $response; 
$count = count($r); 
?> 
<table border="1"> 
<tr> 
    <th>Code</th> 
    <th>Title</th>   
    <th>Author</th>   
    <th>Publisher</th>   
</tr> 
<?php 
for($i=0;$i<=$count-1;$i++){ 
?> 
<tr> 
    <td><?php echo $r[$i]['cd'];?></td> 
    <td><?php echo $r[$i]['title'];?></td> 
    <td><?php echo $r[$i]['author'];?></td>     
    <td><?php echo $r[$i]['publisher'];?></td>   
</tr> 
<?php 
} 
?> 
</table> 
<?php 
} 

は、レコード(配列)を返すために、私は何をすべきかの変更......クライアントのコードですか?

答えて

0

SOAP宣言で戻り値がどのように定義されていますか?

$server->register('addGroupRequest',    // method name 
array('auth_name' => 'xsd:string', 
    'password' => 'xsd:string', 
    'group_objid' => 'xsd:int',   // input parameters 
    'source_character_objid' => 'xsd:int',   // input parameters 
    'message' => 'xsd:string'),   // input parameters 
array('ResultObject' => 'tns:ResultObject'),  // output parameters 
'urn:Groupwsdl',      // namespace 
'urn:Groupwsdl#addGroupRequest',    // soapaction 
'rpc',        // style 
'encoded',       // use 
'add group request for the character '   // documentation 
); 

そして配列を取得するために、私はちょうど$return['addl_info']または$return['result']を呼び出す:

$server->wsdl->addComplexType('ResultObject', 
'complexType', 
'struct', 
'all', 
'', 
     array(
     'result' => array('name' => 'result', 
      'type' => 'xsd:string'), 
     'addl_info' => array('name' => 'addl_info', 
      'type' => 'xsd:string') 
    ) 
); 

はここで同じWSDLの私の機能の登録である:例えば、ここで私は、WSDLを持っているものです。