Convert the .NET dataset to an XML document before returning it through a .NET webservice.


Although this solution doesn’t add complete dataset support to Flex it at least allows you to get the records of a .NET dataset (or a datatable) in Flex through an easy webservice call.

Up till now the typical suggestion is to create a class in .NET that matches the datatable layout, create an array based on this class and fill the array with the records of the datatable.

There is however a much easier solution:

Your WebMethod in .NET should look like this:

[WebMethod]
public XmlDocument GetAllUsers()
{
dsBC dsBC1 = new dsBC();
// here you should fill the datatable in the dataset
return
GetXml(dsBC1.bcUser);
}

public XmlDocument GetXml(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;
}

When calling the GetAllUsers web method from Flex you can simply bind for example a datagrid to the event.result object.

Dates are returned in W3C format by .NET! Therefore you should convert them to ‘real’ Flex dates by using the DateUtil routines in corelib.

Advertisements

~ by mjcprasad2000 on December 27, 2008.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: