所以伙计们,我尝试从我的网站服务调用我的函数,该服务的返回类型为List<string[]>
:
SQLService.SQLServiceClient proxy = new SQLService.SQLServiceClient();
List<string[]> objekte = await proxy.GetObjekteAsync();
然后我收到了这个错误:
“
System.Collections.ObjectModel.ObservableCollection< System.Collections.ObjectModel.ObservableCollection< string>>
”类型不能 转换为System.Collections.Generic.List< string[]>
这是我的函数GetObjekte()
:
public List<string[]> GetObjekte()
{
List<string[]> objektliste = new List<string[]>();
sqlcon.Open();
SqlCommand getObjekte = new SqlCommand("SELECT * FROM [demo]", sqlcon);
SqlDataReader reader = getObjekte.ExecuteReader();
while (reader.Read())
{
string[] stringarry = new string[3];
stringarry[1] = reader["Beschreibung"].ToString();
stringarry[2] = reader["Lief_ an Adresse"].ToString();
stringarry[3] = Convert.ToString(reader["Lief_ an PLZ-Code"] + " " + reader["Lief_ an Ort"]);
objektliste.Add(stringarry);
}
sqlcon.Close();
return objektliste;
}
我不知道为什么Visual Studio认为它有:
System.Collections.ObjectModel.ObservableCollection< System.Collections.ObjectModel.ObservableCollection< string>>
作为返回类型......我在这里看不到我的错误。也许有些人可以帮助我...
我的webservice类的整个代码:
namespace SQLService
public class SQLService : ISQLService
{
SqlConnection sqlcon = new SqlConnection("server=; Database=; Uid=; Pwd=");
public List<string[]> GetObjekte()
{
List<string[]> objektliste = new List<string[]>();
sqlcon.Open();
SqlCommand getObjekte = new SqlCommand("SELECT * FROM [demo]", sqlcon);
SqlDataReader reader = getObjekte.ExecuteReader();
while (reader.Read())
{
string[] stringarry = new string[3];
stringarry[1] = reader["Beschreibung"].ToString();
stringarry[2] = reader["Lief_ an Adresse"].ToString();
stringarry[3] = Convert.ToString(reader["Lief_ an PLZ-Code"] + " " + reader["Lief_ an Ort"]);
objektliste.Add(stringarry);
}
sqlcon.Close();
return objektliste;
}
}
我的界面:
namespace SQLService
{
[ServiceContract]
public interface ISQLService
{
[OperationContract]
List<string[]> GetObjekte();
}
}
答案 0 :(得分:1)
首先更新服务引用,以将集合类型生成为System.Array
然后更新客户端代码......
var proxy = new SQLService.SQLServiceClient();
List<string[]> objekte = (await proxy.GetObjekteAsync()).ToList();