View comments | RSS feed

Using data services

Flex is designed to interact with several types of services that provide access to local and remote server-side logic. For example, a Flex application can connect to a web service that uses the Simple Object Access Protocol (SOAP), a Java object residing on the same application server as Flex using AMF, or an HTTP URL that returns XML. AMF is the protocol used in Flash Remoting MX. The MXML components that provide data access are called data service components. MXML includes the following types of data service components:

The following example shows an application that calls a web service that provides weather information, and displays the current temperature for a given ZIP code. The application binds the ZIP code that a user enters in a TextInput control to a web service input parameter. It binds the current temperature value contained in the web service result to a TextArea control.

<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml" >

   <!-- Define the web service connection
      (the specified WSDL URL is not functional). -->
   <mx:WebService id="WeatherService"      wsdl="/ws/WeatherService?wsdl">

      <!-- Bind the value of the ZIP code entered in the TextInput control
         to the ZipCode parameter of the GetWeather operation. -->
      <mx:operation name="GetWeather">
         <mx:request>
            <ZipCode>{zip.text}</ZipCode>
         </mx:request>
      </mx:operation>

   </mx:WebService>
   <mx:Panel title="My Application" marginTop="10" marginBottom="10"
      marginLeft="10" marginRight="10" >

      <!-- Provide a ZIP code in a TextInput control. -->
      <mx:TextInput id="zip" width="200" text="Zipcode please?"/>

   <!-- Call the web service operation with a Button click. -->
      <mx:Button width="60" label="Get Weather"
         click='WeatherService.GetWeather.send()'/>

      <!-- Display the location for the specified ZIP code. -->
      <mx:Label text="Location:"/>
      <mx:TextArea text="{WeatherService.GetWeather.result.Location}"/>

      <!-- Display the current temperature for the specified ZIP code. -->
      <mx:Label text="Temperature:"/>
      <mx:TextArea text="{WeatherService.GetWeather.result.CurrentTemp}"/>
   </mx:Panel>
</mx:Application>

The following figure shows the application rendered in a web browser window:


Data binding example.

For more information about using data services, see Managing Data in Flex in Developing Flex Applications.


Version 1.5

Comments


jrunrandy said on Sep 6, 2005 at 1:36 PM :
In Flex, you access databases through the WebService, HTTPService, and RemoteObject tags.

Best regards,
Randy Nielsen
Flex IMD Manager
No screen name said on Sep 6, 2005 at 10:10 AM :
what about database access?

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flex/15/flex_docs_en/00000020.htm