我有一個Web服務和一個返回字符串列表的方法。當我在Windows Phone應用程序中調用它並將其放入ListBox時,結果爲System.Data.SqlClient.SqlDataReader。我是網絡服務新手,我不知道問題是出自Web服務還是來自windors手機。 這裏是我的代碼:從網絡服務調用Web服務函數從Windows Phone返回一個字符串[]
方法:
public string [] GetActions(string cnp)
{
string[] lista = new string[300];
try
{
con.Open();
SqlCommand cmd = new SqlCommand("select Denumire from Actiuni where cnp='"+cnp+"'", con);
SqlDataReader re = cmd.ExecuteReader();
int k = 0;
while (re.Read())
{
lista[k++] = re.ToString();
}
re.Close();
}
catch (SqlException exception)
{
}
finally
{
con.Close();
}
return lista;
}
這裏是我的Windows Phone代碼:
public void DesplayActions()
{
ServiceReference1.Service1SoapClient client = new ServiceReference1.Service1SoapClient();
client.GetActionsCompleted += client_ValidareActiuniCompleted;
client.GetActionsAsync(cnp);
}
void client_GetActionsCompleted(object sender, ServiceReference1.GetActionsCompletedEventArgs e)
{
for(int i=0;i<e.Result.Count;i++)
Listbox1.Items.Add(e.Result[i]);
}
private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
DesplayActions();
}
請添加一些更多細節 - 目前還不清楚你想解決的問題是什麼。 –