return Dataset from WebService

J

Joe

I can't seem to get this working right...

Here's what I'm doing:

// in the web service
System.IO.StringWriter sw = new System.IO.StringWriter();
// Fill the dataset
....
dataSetMyData.WriteXml(sw, XmlWriteMode.DiffGram);
string s = sw.ToString();

return s;

In the calling app:

// I get the Xml from the service. This works fine.
string dataSetAsString = ws.GetMyData();

System.IO.StringReader xmlString = new
System.IO.StringReader(dataSetAsString);

DataSet ds = new DataSet("Tree data");

ds.ReadXml(new
System.IO.MemoryStream(System.Text.Encoding.Default.GetBytes(dataSetAsString
) ) );
ds.ReadXml(xmlString);

// I want to iterate through the dataset and add the items to a treeview
// but there are no items.
foreach (DataTable t in ds.Tables)
{
foreach(DataRow dr in t.Rows)
treeView1.Nodes.Add(dr.ItemArray.ToString() );
}

I also tried to do a ds.WriteXml("C:\\Temp\\MyXml.xml"); but it doesn't
contain any records.
Is there something I'm not doing to poplate the DataSet?
 
M

Manuj Aggarwal

how about if you just return the DataSet itself without trying to serialize
it yourself.

e.g.

[WebMethod()]
public DataSet GetData()
{
}

ASP.NET will automatically serialize it on the server and if you have .NET
client - it will automatically deserialize the return dataset.

HTH
Manuj Aggarwal
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top