How to call a function that returns an array from a web service?

I am new to C # and I use nuSOAP and PHP. I encoded a function in a web service that returns an array. The problem is that I do not know how to get this array from the client side. Here is the relevant code in my web service:

function GetSection(bool $wcoloumn,string $coloumn, bool $all){ if($wcoloumn== true && $all==false){ $SQL = "SELECT `$coloumn` FROM _sections"; $result = mysql_query($SQL); $dataCOL = array(); $index = 0; $num = mysql_num_rows($results); while($row = mysql_fetch_assoc($result)) // loop to give you the data in an associative array so you can use it however. { if ($num > 0) { // You have $row['ID'], $row['Category'], $row['Summary'], $row['Text'] $dataCOL[$index] = $row['$coloumn']; $index++; } } return $dataCOL(); } } 

This is a function that returns an array [ $dataCOL(); ] [ $dataCOL(); ] .

Also note that I added my own complex type (array):

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

I also registered this function:

 $server->register('GetSection', array('wcoloumn' => 'xsd:boolean', '$coloumn' => 'xsd:string', 'all' => 'xsd:boolean'), array('result' => 'tns:ArrayOfString')); 

Client-side code is written in C # and currently looks like this:

 public static userdatawsdl webs = new userdatawsdl(); public String[] arrSections = webs.GetSection(true, "id", false); public String[] GetAppSections(bool wcoloumn,string coloumn) { return arrSections[]; // Here I get syntax error :D } 

The error I get is only on the client side:

Syntax error; expected value

What could be the problem?

+4
source share
1 answer

Your problem here is converting an array to an array of strings, try using Linq

 public String[] GetAppSections(bool wcoloumn,string coloumn) { string[] foo = webs.GetSection(true, "id", false).OfType<object>().Select(o => o.ToString()).ToArray(); return foo } 
+2
source

All Articles