<

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x

Asp.Net Web Service for Different Platforms

Published on
8,575 Points
2,575 Views
Last Modified:
Approved
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
Comment
0 Comments

Featured Post

Discover the Answer to Productive IT

Discover app within WatchGuard's Wi-Fi Cloud helps you optimize W-Fi user experience with the most complete set of visibility, troubleshooting, and network health features. Quickly pinpointing network problems will lead to more happy users and most importantly, productive IT.

Join & Write a Comment

The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
Discover the basics of using Outlook 2016 from office 365.

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month