I have searched for a long time and tried different ways to solve this problem without any success.
My current program is as follows:
I receive a string array in the DAL that I try to send through the web service to my Controller
in the windows form program. But receive the error:
Cannot implicity convert type 'WindowsFormApplication.ServiceReference1.ArrayOfString' to 'System.Collections.Generic.List<string[]>'
Controller in form:
public List<string[]> GetAllEmployee()
{
return client.GetAllEmployee();
}
Webservice:
public List<string[]> GetAllEmployee()
{
return cont.GetAllEmployee();
}
DAL:
public List<string[]> GetAllEmployee()
{
GetConnection();
con.Open();
stmt = con.CreateCommand();
stmt.CommandText = "SELECT [No_],[First Name],[Last Name],[Initials],[Job Title],[E-Mail] FROM [CRONUS Sverige AB$Employee]";
OdbcDataReader reader = stmt.ExecuteReader();
List<string[]> allEmployee = new List<string[]>();
String[] cols = new string[5];
for (int i = 0; i < cols.Length; ++i)
{
cols[i] = reader.GetName(i);
}
allEmployee.Add(cols);
while (reader.Read())
{
string[] s = new string[cols.Length];
for (int i = 0; i < s.Length; ++i)
{
s[i] = reader.GetValue(i).ToString();
}
allEmployee.Add(s);
}
con.Close();
return allEmployee;
}
Controller:
public List<string[]> GetAllEmployee()
{
return dal.GetAllEmployee();
}
client:
ServiceReference1.WebService1SoapClient client = new ServiceReference1.WebService1SoapClient();
您的服务返回WindowsFormApplication.ServiceReference1.ArrayOfString
类型,需要使用ToList方法将其显式转换为List<string>
:
return dal.GetAllEmployee().ToList();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.