LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   PHP SOAP server returns array using NuSOAP Library (https://www.linuxquestions.org/questions/programming-9/php-soap-server-returns-array-using-nusoap-library-600470/)

mohtasham1983 11-17-2007 05:42 PM

PHP SOAP server returns array using NuSOAP Library
 
Hi,
I have a function in my SOAP server that returns an array. When the client calls this function, it only receives "array", and when I use foreach to print each member of this array, it tells me that this is not an array. If I change the returned value of the function to a string or integer type everything works fine though, so I don't think that there is any problem with the client.

I am using NuSOAP library on php to achieve that.

I had doubt when declaring the type of return value of the function. In XML schema there is no array type, so I specified the return value as a string like this:

PHP Code:

$server->register("getLocation",
                array(
'country_population' => 'xsd:string',
                
'city_population' => 'xsd:string'),
                array (
'return' => 'xsd:string'),
                
'urn:world',
                
'urn:worldquote#getLocation'); 

The return values is a result of a query from database.

Any idea how I can declare array element in XML schema?

Guttorm 11-18-2007 10:10 AM

Hi

In the register call, you are saying that your function returns a string. You need to make the type yourself. Something like:

PHP Code:

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

Then, when use something like this for return type:
PHP Code:

array("return" => "tns:ArrayOfString"), 

instead of
PHP Code:

array ('return' => 'xsd:string'), 

Haven't tested it, but I coded something like that before, but I don't have it here now.

mohtasham1983 11-18-2007 09:27 PM

thanks, I got it working. I really appreciate your help.


All times are GMT -5. The time now is 11:53 AM.