2010-04-11 64 views
0

我想在我的web服務nusoap可以返回字符串的字符串嗎?

我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

您不能像這樣返回數組。要返回一個數組,你必須定義一個複雜的類型。 我將提供U上的一個例子...

服務器程序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); 
?>