I'm working on a webservice project where I'm using sql-server to extract data from a specific database to later send it to one or more clients such as Java applications and C# forms. Right now I'm connecting methods to a C# form and I'm having trouble to convert or in other words deserialize arrayofstring from xml to a List in c#.
I have done a converting method but its in my webservice, it looks like:
public List<List<string>> Converter(SqlDataReader sdr)
{
if (sdr != null)
{
List<List<string>> list = new List<List<string>>();
while (sdr.Read())
{
List<string> tmp = new List<string>();
for (int i = 0; i < sdr.FieldCount; i++)
{
string parameter = "";
try
{
if (sdr.GetFieldType(i) == typeof(string))
{
parameter = sdr.GetString(i);
}
if (sdr.GetFieldType(i) == typeof(int))
{
parameter = sdr.GetInt32(i).ToString();
}
}
catch (SqlException e)
{
Debug.WriteLine(e.Message);
}
tmp.Add(parameter);
}
list.Add(tmp);
}
return list;
}
return null;
}
This Method Converter will convert my arrayofstrings to List<string>
but once I call the method in my proxy or controller it goes back to ArrayOfStrings.
My Proxy aka Controller:
class Controller
{
WebService1SoapClient client = new WebService1SoapClient();
public List<List<string>> GetAllKeys()
{
List<List<string>> list = new List<List<string>>();
List<string> tmp = new List<string>();
var obj = client.GetAllKeys();///<--- when the method is called it should be List<string> type
//but the WebService1SoapClient client = new WebService1SoapClient(); wont let the convert List<string> go through.
foreach (var item in obj) //
{
tmp.Add(item.ToString());
}
list.Add(tmp);
return list;
}
private void getListStrings()
{
List<string> list = client.GetAllKeys().ToList<string>();
// cannot convert ArrayOfString to List<string> (what I want to do).
List<string> list = new List<String>(arr);
foreach (string item in client.GetAllKeys())
{
list.Add(item);
}
}
}
}
Note that the controller is in an other solution I'm running two visual studios or solutions 1.Webservice and 2. My c# win application where my controller is.
How can I convert ArrayOfstrings to List<string>
?