开发者

Can nusoap returns arrray of string?

I would like to return an array of string in my web services

I've tryed :

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

$server = new soap_server();
$server->configureWSDL('NewsService', 'urn:NewsService');
$server->register('GetA开发者_如何学运维llNews', 
 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;
}

but it doesn't work. What is the correct syntax for that ?

Thanks in advance for any help


You can't return an array like this. To return an array, you have to define a complex type. I'll provide u an example...

The server program 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' =>'test@a.com',
       '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);
?>

And the client program 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);
?>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜