Can nusoap return a string array?

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

I tried:

<?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 that will not work. What is the correct syntax for this?

Thanks in advance for your help.

+6
web-services nusoap
source share
3 answers

First you need to define a new type that describes an array of such strings:

 $server->wsdl->addComplexType( 'ArrayOfString', 'complexType', 'array', 'sequence', '', array( 'itemName' => array( 'name' => 'itemName', 'type' => 'xsd:string', 'minOccurs' => '0', 'maxOccurs' => 'unbounded' ) ) ); 

Then you can use tns:ArrayOfString as the return type.

+9
source share

This site describes a good way to return complex data types and get it using C #: http://sanity-free.org/125/php_webservices_and_csharp_dotnet_soap_clients.html

+1
source share

When returning an array of arrays, you may need a different configuration from Oliver. For example, phfunc2php uses this technique in the nusoapcode.class.php file ( https://github.com/sylnsr/pgfunc2php/blob/master/nusoapcode.class.php ). The generated code looks like this:

 $server->wsdl->addComplexType( 'ArrayOfArrays','complexType','array','', 'SOAP-ENC:Array', array(), array(array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'xsd:string[]'))); 

and then the functions just have to return "tnsArrayOfArrays:

 $server->register( 'sel_signon_id_by_uuid', array('user_uuid' => 'xsd:string'), array('return'=>'tns:ArrayOfArrays'), 

The above project can compile working code for you if you want to see it.

+1
source share

All Articles