2010-04-11 2 views
0

나는 내 웹 서비스 nusoap이 문자열 arrray를 반환 할 수 있습니까?

내가 tryed했습니다

에서 문자열의 배열을 반환하고 싶습니다 :

<?php 
require_once('nusoap/nusoap.php'); 

$server = new soap_server(); 
$server->configureWSDL('NewsService', 'urn:NewsService'); 
$server->register('GetAllNews', 
array(), 
array('return' => 'xsd:string[]'), 
'urn:NewsService', 
'urn:NewsService#GetAllNews', 
'rpc', 
'literal', 
'' 
); 

// Define the method as a PHP function 
function GetAllNews() 
{ 
$stack = array("orange", "banana"); 
array_push($stack, "apple", "raspberry"); 
return $stack; 
} 

그러나 그것은 작동하지 않습니다. 올바른 구문은 무엇입니까? 어떤 도움

답변

0

에 미리

덕분에이 같은 배열을 반환 할 수 없습니다. 배열을 반환하려면 복합 유형을 정의해야합니다. 내가 유에게 예를 제공합니다 ...

service.php 서버 프로그램 :

<?php 
// Pull in the NuSOAP code 
require_once('lib/nusoap.php'); 
// Create the server instance 
$server = new soap_server(); 
// Initialize WSDL support 
$server->configureWSDL('RM', 'urn:RM'); 

//Define complex type 
$server->wsdl->addComplexType(
'User', 
'complexType', 
'struct', 
'all', 
'', 
array(
    'Id' => array('name' => 'Id', 'type' => 'xsd:int'), 
    'Name' => array('name' => 'Name', 'type' => 'xsd:string'), 
    'Email' => array('name' => 'Email', 'type' => 'xsd:string'), 
    'Description' => array('name' => 'Description', 'type' => 'xsd:string') 
) 
); 


// Register the method 
$server->register('GetUser',  // method name 
array('UserName'=> 'xsd:string'),   // input parameters 
array('User' => 'tns:User'),  // output parameters 
'urn:RM',   // namespace 
'urn:RM#GetUser',  // soapaction 
'rpc',   // style 
'encoded',   // use 
'Get User Details'  // documentation 
); 

function GetUser($UserName) { 

    return array('Id' => 1, 
     'Name' => $UserName, 
     'Email' =>'[email protected]', 
     'Description' =>'My desc' 
     ); 

} 

// Use the request to (try to) invoke the service 
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : ''; 
$server->service($HTTP_RAW_POST_DATA); 
?> 

그리고 클라이언트 프로그램 client.php :

<?php 
// Pull in the NuSOAP code 
require_once('lib/nusoap.php'); 
// Create the client instance 
$client = new soapclient('http://localhost/Service/service.php'); 
// Call the SOAP method 
$result = $client->call('GetUser', array('UserName' => 'Jim')); 
// Display the result 
print_r($result); 
?>