NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
Return an array of structs from server


Joined: 31 May 2006
Posts: 1
Reply with quote
I am trying to implement a web service using nusoap that returns an array of structures (i.e. a row/column data structure).

Using the example shown at , I set up the following:

Code:
$server = new soap_server();
$server->configureWSDL('PromptSearch',$ns);
$server->wsdl->schemaTargetNamespace=$ns;
//define complex types for returned array of prompt information
$server->wsdl->addComplexType(
    'prompt',
    'complexType',
    'struct',
    'all',
    '',
    array(
        'id' => array('name'=>'id','type'=>'xsd:string'),
        'filename' => array('name'=>'filename','type'=>'xsd:string'),
        'text' => array('name'=>'text','type'=>'xsd:string'),
        'language' => array('name'=>'language','type'=>'xsd:string'),
        'voice' => array('name'=>'voice','type'=>'xsd:string'),
        'misc' => array('name'=>'misc','type'=>'xsd:string')
       )
);
$server->wsdl->addComplexType(
    'promptset',
    'complexType',
    'array',
    '',
    'SOAP-ENC:Array',
    array(),
    array(
        array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:prompt[]')
    ),
    'tns:promptset'
);
$server->register('PromptSearch',
array( // inputs
   'searchstring' => 'xsd:string',
   'language' => 'xsd:string',
   'voice' => 'xsd:string',
   'application' => 'xsd:string',
   'target' => 'xsd:string'
   ),
array('return'=>'tns:promptset'), // output
$ns);


In the registered function I build up an array of associative arrays that match the struct:

Code:
function PromptSearch($searchstring, $language, $voice, $application, $target){

    // Initialize promptset array
   $promptset = array();
    for($i = 1; $i <= 2; $i++) {
        // Generate a prompt
        $prompt = array(
        'id' => $i,
        'filename' => 'prompt_' . $i,
        'text' => 'This is some text from prompt ' . $i,
        'language' => 'en_us',
        'voice' => 'chris',
        'misc' => 'Indeed this is prompt' . $i);
        $promptset[] = $prompt;
    }

    //print_r($promptset);
    return $promptset;
}
$server->service($HTTP_RAW_POST_DATA);


When I run a client against this service (also written in nusoap) it returns an array of empty arrays:

Code:
Array ( [0] => Array ( [0] => Array ( ) [1] => Array ( ) [2] => Array ( ) [3] => Array ( ) [4] => Array ( ) [5] => Array ( ) ) [1] => Array ( [0] => Array ( ) [1] => Array ( ) [2] => Array ( ) [3] => Array ( ) [4] => Array ( ) [5] => Array ( ) ) )


I suspect that my "addComplexType" statement for "promptset" is not correct, butI have not been able to find any other examples.

Can anyone provide a working example of this kind of return implemented in nusoap, or point out whet I am doing wrong?

Thanks!
View user's profileFind all posts by hmbjeffSend private message


Joined: 28 Apr 2008
Posts: 4
Reply with quote
I hope this one will help. It works for me.
View user's profileFind all posts by tristanSend private message
Return an array of structs from server
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT - 5 Hours  
Page 1 of 1  

  
  
 Reply to topic