HTTPService provides a useful interface for REST Web Services however asynchronous service calls can be difficult to validate and debug.
Solution
The EzHTTPService Object makes using REST Web Services very easy.
Detailed explanation
The EzHTTPService is a collection of three ActionScript 3.0 files that together forms a rather useful composite Object. The Problem The problem we were trying to resolve with the development of the EzHTTPService was one that was not well understood when we began to work with Flex Builder 2.0.1 some months ago.
Initially we went HTTPService crazy and used a bunch of HTTPService Objects scattered around our code.
We did not realize each HTTPService Object was capable of issuing an asynchronous REST Web Service call, and we quickly found the faster running Web Services were being executed sooner than the slower running Web Services.
Also we noticed our debugging interface for our Web Services, which were coded in PHP 5.2.0, was not giving us reliable feedback.
We used the RPC Model for our REST Web Services where all our web service code was in the same PHP file.
We needed to validate our server-side logic so we chose to resolve the asynchronous problem by creating a wrapper for HTTPService.
The Solution Our solution was to create a wrapper for HTTPService that performs the following functions:
HTTPService is executed in a serial manner which means the previous request must complete before the next one is executed.
REST Web Service RPC Requests are cached whenever the HTTPService Object is busy.
Error Handling is built into EzHTTPService which means whenever an error happens in the CallBack function or the code that processes the HTTPService call that error is handled via a pop-up that displays the error message with some diagnostic information.
Whenever any HTTPService call completes EzHTTPService checks to see if there is another HTTPService call in the queue and the next REST Web Service call is executed whenever one is available.
We added some functions for handling Results that come back from our REST Web Service calls to ensure the data objects are always presented to us as ArrayCollection Objects – sometimes Flex likes to present singleton objects as an Object instance rather than an ArrayCollection and null values which should be empty ArrayCollection objects are also problematic.
We also added some function to help convert HTML for transmission to/from ASP.Net Web Services since we noticed ASP.Net had some problems when dealing with embedded HTML – our fix was to convert “<” and “>” to “<” and “>” respectively.
We added support for passing a UserID as part of every REST Web Service call because the code we were writing was running behind a Firewall as an Intranet Web App and we used ASP.Net to detect the UserID via the current user context.
We added support for handling the Debug Mode so we could capture an HTML based Debug Log from our server-side code when we wanted to and not the rest of the time.
We exposed a CallBack for the Alert pop-up to allow those who use our EzHTTPService objects to control how errors are handled.
We exposed a CallBack for the OnFault to allow those who use our EzHTTPService objects to control how errors are handled.
In Conclusion As you may be able to tell by now the EzHTTPService object which is a single SWC you too can use, is a nice collection of reusable functionality you also might find useful.
EzHTTPService presents a single point of failure for your REST Web Service calls.
Running REST Web Services one at a time allowed us to validate our service-side logic and control the state of the database since sometimes we wanted to push data into the database with the ability to pull a list of data from the database and running these Web Service calls in a serial manner allows us to resolve some issues of an asynchronous nature.
Error handling and error reporting as well as the general stability of our REST Web Service Flex projects are enhanced by using EzHTTPService.
The RPC Model allowed us to capture usage metrics in the form of a database table into which we placed the RPC Command name as well as the parameters and the User’s ID and the date timestamp. This allowed us to track the parts of the system users were using more often so we could spend time optimizing those areas a bit more than others.
We are sure you will find the EzHTTPService object useful for your next project.
You can download the EzHTTPService SWC from our site.