c# – 如何调用从Web服务返回数组的函数?

我是C#的新手,我正在使用nuSOAP和
PHP.我在一个返回数组的Web服务中编写了一个函数.问题是我不知道如何从客户端获取该数组.这是我的网络服务中的相关代码:

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();
    }
    }

这是返回数组的函数[$dataCOL(); ].

另请注意,我添加了自己的复杂类型(数组):

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

我也注册了这个功能:

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

客户端代码是用C#编写的,目前看起来像这样:

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
}

我得到的错误只在客户端:

Syntax error; value expected

这可能是什么问题?

最佳答案 你的问题是将数组转换为字符串数组,尝试使用Linq

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