return Dataset from WebService

Discussion in 'ASP .Net Web Services' started by Joe, May 8, 2004.

  1. Joe

    Joe Guest

    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?
     
    Joe, May 8, 2004
    #1
    1. Advertising

  2. 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

    "Joe" <> wrote in message
    news:...
    > 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?
    >
    >
     
    Manuj Aggarwal, May 8, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nedu N
    Replies:
    1
    Views:
    1,838
    Chris Taylor
    Oct 31, 2003
  2. Greenhorn
    Replies:
    15
    Views:
    884
    Keith Thompson
    Mar 6, 2005
  3. Jeff

    error parsing dataset upon return from webservice

    Jeff, Jul 23, 2003, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    183
  4. Mike Morisoli

    Proper way to return a Dataset to InfoPath from a WebService

    Mike Morisoli, Apr 24, 2004, in forum: ASP .Net Web Services
    Replies:
    2
    Views:
    295
    Mike Morisoli
    Apr 24, 2004
  5. Return dataset in my webservice with schema

    , Oct 7, 2008, in forum: ASP .Net Web Services
    Replies:
    1
    Views:
    223
    John Saunders
    Oct 7, 2008
Loading...

Share This Page