Showing posts with label flex. Show all posts
Showing posts with label flex. Show all posts

Saturday, July 28, 2007

Getting .NET datasets in Flex through webservices

The current support in Flex for .NET datasets is rather 'limited' to say the least. This is a pitty because most .NET developers make use of datasets and the missing support currently prevents major adoption of Flex by the .NET community.

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 with database records
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.

Thursday, March 15, 2007

Too enthousiastic Flex caching

I've been trying to call a dynamic ASP.NET webpage multiple times (each time the page returns different information).

It seems that Flex is, by default, caching the response. The 'ugly' way is to append some unique id at the end of the url to force a new request (http://somewebsite/stockquotes.aspx?ID=1, http://somewebsite/stockquotes.aspx?ID=2, ...).

There is however also a 'nice' way to solve the problem (at least if you have access to the ASP.NET source code). Just add the following code to your ASP.NET page (for example in the Page_Load method): Response.Cache.SetCacheability(HttpCacheability.NoCache);