<

Asp.Net Web Service for Different Platforms

Published on
8,433 Points
2,433 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

Prepare for an Exciting Career in Cybersecurity

Help prevent cyber-threats and provide solutions to safeguard our global digital economy. Earn your MS in Cybersecurity. WGU’s MSCSIA degree program curriculum features two internationally recognized certifications from the EC-Council at no additional time or cost.

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…
The video will let you know the exact process to import OST/PST files to the cloud based Office 365 mailboxes. Using Kernel Import PST to Office 365 tool, one can quickly import numerous OST/PST files to Office 365. Besides this, the tool also comes…
Suggested Courses

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month