views:

154

answers:

3

Hi all,

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('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;
}

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

Thanks in advance for any help

A: 

U can't return an array like this.... To return an array u hav to define a complex type... I'll provide u an example... Hope it helps u...

simran
A: 

Check the code below.......

simran
A: 

U can't return an array like this.... To return an array u hav to define a complex type... I'll provide u an example... Hope it helps u...

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' =>'[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);
?>

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);
?>
simran