ódigo de serviço @Web não retornando matriz de String
Eu quero retornar uma matriz de Strings no formato "abc # xyz # ghi # tru" (onde # é delimitador) do meu método de serviço da web. No entanto, eu não sou capaz de fazê-lo. Aqui está o meu código de serviço da web atual:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.Data.SqlClient;
namespace WebService10
{
/// <summary>
/// Summary description for Service1
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment
the following line.
// [System.Web.Script.Services.ScriptService]
public class Service1 : System.Web.Services.WebService
{
String[] result=new String[40];
String[] result2 = new String[40];
[WebMethod]
public String[] getData()
{
SqlConnection myConnection = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=student;User ID=sa;Password=123");
try
{
myConnection.Open();
SqlCommand myCommand = new SqlCommand();
myCommand.Connection = myConnection;
myCommand.CommandText = "select count(*) from names where name =@name";
SqlDataReader myReader = myCommand.ExecuteReader();
//while
for(int i=0;i<40;i++)
{
if (myReader.Read())
{
result[i]= myReader["name"].ToString();
result2[i] = result[i] + "#";
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
myConnection.Close();
}
return result2;
}
}
}
Alguém pode me dizer o que há de errado com meu código?