Asp.Net Web Service for Different Platforms

Published:
When coding a Webservice to provide data, the normal way is to create a method that returns a Dataset object.   But a Dataset cannot be used easily from another platform, such as PHP,  FLAS (FLEX) , etc.

Solution :
Return a XML Document instead  of Dataset .

Coding  like :
[WebMethod]
                      public XmlDocument MydataProvided()
                      {
                         Dataset DS = new DataSet ()
                         // here you should write some login to fill  the dataset
                         return GetDSXml(DS);
                      }
                      
                      public XmlDocument GetDSXml(Dataset  ds)
                      {
                         System.IO.StringWriter sw = new System.IO.StringWriter();
                         ds.WriteXml(sw);
                         sw.Close();
                         XmlDocument xd = new XmlDocument
                         xd.LoadXml(sw.ToString());
                         return xd;
                      }

Open in new window


Also, by adding the following method a DataTable can be returned easily.

public XmlDocument GetDtXml(DataTable  dt)
                      {
                         System.IO.StringWriter sw = new System.IO.StringWriter();
                         dt.WriteXml(sw);
                         sw.Close();
                         XmlDocument xd = new XmlDocument
                         xd.LoadXml(sw.ToString());
                         return xd;
                      }

Open in new window

0
3,055 Views

Comments (0)

Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.