Among the many Flex Builder 4 new features there is the possibility to import REST web services into ActionScript classes, in the same way that the previous builder allowed to import SOAP web services. It can import from XML as well as from JSON data. This new feature can obviously be used to import into ActionScript any kind of services that dynamically generate XML or JSON content.
For the following example I used the MAX preview version of Flex Builder 4, which has many interesting features and, while not yet complete, will become a very good IDE. The example will use a very simple JSP that returns some XML data, dynamically generated as a response to the client invocation. The JSP has contentType="text/xml;", accepts a numeric parameter length and returns a simple structure, with as many nodes as the length parameter. The service called with length=2 will return:
<root>
<content value="0"/>
<content value="1"/>
</root>
Now we can go to Flex Builder 4 and open the HTTP Service import dialog, right next to the Web Service one. The wizard will ask for the URL of the remote service and will be able to add the parameters accepted by the service. It is possible to define more operations, their parameters and request methods and also import as many HTTP services as we need. The next step will be the creation of the ActionScript classes, by selected the previously defined operations and configure the return type: the wizard will create all necessary classes and the methods to invoke the service, will hide from the developer the conversion between XML/JSON and ActionScript and provide with a transparent and object oriented set of classes ready to be used.
For the above XML the following classes have been created:
Content.as - with a value property;
XMLServiceTest - a class containing all the operations to be invoked on this service.
Both of these classes extend a base class, which contains the generated code, so we can safely modify the extending classes, as only the base ones would be overwritten in case of service changes.
Other interesting features of the new builder allow us to rapidly test the newly created services or even to enable paging and data management. By selecting a generated operation and the main application file we can have the builder generate a test datagrid and also all required events for it to work:
<DataGrid id="DataGrid1" dataProvider="{result1.lastResult}">
<columns>
<DataGridColumn headerText="value" dataField="value"/>
</columns>
</DataGrid>
With a few clicks we have an application that exchanges strong typed data with a remote server, on top of XML/JSON.
By allowing a transparent conversion between XML/JSON data and ActionScript classes, this HTTP Service import feature makes the development easier for enterprise applications that use REST services or plain XML or JSON as a means of communication.
Comments (8)
REST is huge and it's good to read about the ongoing efforts to support working with REST using Flex Builder. Thanks for the insight.
Posted by Todd Rothe | January 12, 2009 11:24 PM
Posted on January 12, 2009 23:24
Your information is good.....
Posted by web design company,web designer,web design India,website design,web design | January 29, 2009 7:48 AM
Posted on January 29, 2009 07:48
Hi,
I have downloaded the flex sdk 4 and added to Flex 3 sdk. But could see the HttpService Wizard. Could you plese help me.
Posted by venkat | May 9, 2009 4:26 AM
Posted on May 9, 2009 04:26
Nice informative post...thanks for sharing.
Posted by Web Design and Web Development | May 11, 2009 2:32 PM
Posted on May 11, 2009 14:32
Hello venkat, the HttpService wizard is a tool integrated in Flex Builder 4 and is not related with the Flex 4 SDK. You will be able to use it when the builder will be released.
Posted by Constantin Moldovanu | May 11, 2009 2:43 PM
Posted on May 11, 2009 14:43
When will Flex Builder 4 be released?
Posted by Stanley Guan | July 31, 2009 7:06 PM
Posted on July 31, 2009 19:06
I have published my recent Actionscript library rest-arm. It can do all rest actions in an easy way. check it
http://code.google.com/p/rest-arm/
Posted by M.Elkharashy | October 2, 2009 1:54 PM
Posted on October 2, 2009 13:54
Great peace of work and the use of the web services in action script with the flex builder!
so good work!
Posted by web designing | October 26, 2009 10:56 AM
Posted on October 26, 2009 10:56