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:
$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:
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:
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!