How to consume WCF method with "DataSet" return type in Silverlight
10+ Methods in my WCF webservice returns an object of type DataSet
public System.Data.DataSet ReturnData()
{
DataSet dataSet = new DataSet();
//do some work on the dataset
return dataSet;
}
I want to consume this WCF webservice in my silverlight application.
Problem: DataSet is not resolved as System.Data.dll does not appear in the Silverlight application's add reference section.
Is there a workaround or a so开发者_运维知识库lution?
Take a look on DataSet for Silverlight Applications
But I advise you to write this into classes
Edit: To show you how you can use instead of the classe, I give you an example
public class Person
{
private int gID;
private String gFirstName="";
private String gLastName = "";
public int ID
{
get
{
return gID;
}
set
{
gID = value;
}
}
public String FirstName
{
get
{
return gFirstName;
}
set
{
gFirstName= value;
}
}
public String LastName
{
get
{
return gLastName;
}
set
{
gLastName = value;
}
}
}
.
public class Persons
{
private List<Person> gListOfPerson;
public List<Person> All
{
get
{
if (gListOfPerson == null)
{
gListOfPerson= new List<Person>();
}
return gListOfPerson;
}
set
{
gListOfPerson=value;
}
}
}
.
public Persons ReturnData()
{
DataSet vDS = new DataSet();
//get data from SQL Server or what ever in a DataSet...
foreach(System.Data.DataTable t in vDS.Tables)
{
Persons vPersons = new Persons();
foreach(System.Data.DataRow dr in t.Rows)
{
Person vPerson = new Person();
int vtryInt;
int.TryParse(dr["ID"].ToString(), out vtryInt);
vPerson.ID = vtryInt;
vPerson.FirstName = dr["FirstName"].toString();
vPerson.LastName = dr["LastName"].toString();
vPersons.All.Add(vPerson);
}
return vPersons ;
}
精彩评论