Adobe
Products
Acrobat
Creative Cloud
Creative Suite
Digital Marketing Suite
Digital Publishing Suite
Elements
Photoshop
Touch Apps
Student and Teacher Editions
More products
Solutions
Digital marketing
Digital media
Education
Financial services
Government
Web Experience Management
More solutions
Learning Help Downloads Company
Buy
Home use for personal and home office
Education for students, educators, and staff
Business for small and medium businesses
Licensing programs for businesses, schools, and government
Special offers
Search
 
Info Sign in
Welcome,
My cart
My orders My Adobe
My Adobe
My orders
My information
My preferences
My products and services
Sign out
Why sign in? Sign in to manage your account and access trial downloads, product extensions, community areas, and more.
Adobe
Products Sections Buy   Search  
Solutions Company
Help Learning
Sign in Sign out My orders My Adobe
Preorder Estimated Availability Date. Your credit card will not be charged until the product is shipped. Estimated availability date is subject to change. Preorder Estimated Availability Date. Your credit card will not be charged until the product is ready to download. Estimated availability date is subject to change.
Qty:
Purchase requires verification of academic eligibility
Subtotal
Review and Checkout
Adobe Developer Connection / Flex Developer Center /

Building web service clients with Flex Builder 3

by Zee Yang

Zee Yang
  • www.flexlive.net/

Created

14 July 2008

Page tools

Share on Facebook
Share on Twitter
Share on LinkedIn
Bookmark
Print
Flex SOAP web services

Requirements

Prerequisites

Working knowledge of SOAP messaging and ActionScript 3.0.

User Level

Intermediate

Required products

  • Flex Builder 3 (Download trial)

Sample files

  • hellows.zip (24 KB)

Web service standards are an important cornerstone of enterprise SOA. While the Flex platform has always had native support for web services, Flex Builder 3 has taken it one step further with a new feature, Web Service Introspection.

Using a modified version of Apache Axis framework, the new Web Service Introspection wizard generates proxy classes that take care of web service data transfer and event plumbing. With this new tool, an application developer can build a web-service–enabled Flex client in minutes!

This article shows how to use the Web Service Introspection Tool, and explains the code it generates for a sample application.

Using the Web Service Introspect wizard

After opening a Flex project in Flex Builder, choose Data > Import Web Service. The wizard will ask for the WSDL URI and a path to save the generated code (see Figure 1). The Web Services Description Language (WSDL) document contains information that a client needs to use the web service.

The Web Service Introspection wizard
Figure 1. The Web Service Introspection wizard

After inspecting the WSDL file, the wizard presents code generation options (see Figure 2). You can select which web service operations to target, and specify the fully qualified name for the ActionScript class.

Code generation options
Figure 2. Code generation options

You can choose Data > Manage Web Services to access the Manage Web Services dialog box, which is useful for updating and deleting WSDL information, as well as managing multiple web services associated with a project (see Figure 3).

The Manage Web Services dialog box
Figure 3. The Manage Web Services dialog box

Understanding the generated Code

Depending on the complexity of the WSDL, there can be an almost overwhelming number of classes generated. The actual mechanics of the generated classes is quite simple, however.

First, look at the class in the <Service Name>.as file (in the example shown in Figure 2, this would be USWeather.as). It's the proxy class that you use to drive the web service calls. Note that the WebService class is no longer used in Flex. All the service calls are made through <Service Name>.as.

In addition, all the web service members are listed in <Service Name>.as as public functions. There are two ways you can invoke a service call:

  • Attach an event handler to a service call. If you come from a Java/.NET background, this is would be the most intuitive approach. After instantiating the main service class, attach an event handler to the service call and proceed to invoke the service call. For example:
private var weather:USWeather = new USWeather(); private function getMyWeather1():void { // Attach the event handler weather.addgetWeatherReportEventListener(handleWeather); // Invoke the service call weather.getWeatherReport("37217"); } private function handleWeather(event:GetWeatherReportResultEvent):void { trace(event.result); }
  • Bind to the last result. This approach leverages the Flex data binding feature and simplifies your code. To make a service call, pass the parameters via <method>_Request_var and invoke <method>_send. The return data will be stored in <method>_lastResult. For example:
[Bindable] private var weather:USWeather = new USWeather(); private function getMyWeather2():void { // Set the input parameter var req:GetWeatherReport_request = new GetWeatherReport_request(); req.ZipCode = "37217"; weather.getWeatherReport_request_var = req; // Invoke the method weather.getWeatherReport_send(); }

All data exchange is done via strongly typed data structures. For example, if you were making a call to getCustomer, which returns a CutomerInfo object, the object type would be defined by the CutomerInfoType class.

Some web service endpoints require basic authentication. To set the credentials, use the setCredentials(), setRemoteCredentials(), and logout()functions from the base class, Base<Service Name>.as.

Where to go from here

The new Web Service Introspection wizard has made developing SOAP clients effortless in Flex. The strongly typed message passing not only gives you a water-tight communication pipe, but it also makes coding much easier in the IDE.

One drawback of using web services is the communication overhead. If your Flex application handles large amount of data, consider using the BlazeDS Remote Object Service instead.

Creative Commons License
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License

More Like This

  • Creating a rich buying experience with a data-driven RIA
  • Building a simple dashboard using Flex 3 with ILOG Elixir
  • Using web services with Data Centric Development in Flash Builder 4 beta

Tutorials & Samples

Tutorials

  • Flex mobile performance checklist
  • Flex and Maven with Flexmojos – Part 3: Journeyman
  • Migrating Flex 3 applications to Flex 4.5 – Part 4

Samples

  • Twitter Trends
  • Flex 4.5 reference applications
  • Mobile Trader Flex app on Android Market

Flex User Forum

More
07/25/2011 Flash Player Debug Issues - Safari 5.1 & Chrome 13
04/22/2012 Loader png - wrong color values in BitmapData
04/22/2012 HTTPService and crossdomain.xml doesn't work as expected
04/23/2012 Memory related crashes in Flex application

Flex Cookbook

More
04/06/2012 How to detect screen resize with a SkinnableComponent
02/29/2012 Embed Stage3D content inside Flex application components
02/15/2012 Custom WorkFlow Component
02/09/2012 Using Camera with a MediaContainer instead of VideoDisplay

Products

  • Acrobat
  • Creative Cloud
  • Creative Suite
  • Digital Marketing Suite
  • Digital Publishing Suite
  • Elements
  • Mobile Apps
  • Photoshop
  • Touch Apps
  • Student and Teacher Editions

Solutions

  • Digital marketing
  • Digital media
  • Web Experience Management

Industries

  • Education
  • Financial services
  • Government

Help

  • Product help centers
  • Orders and returns
  • Downloading and installing
  • My Adobe

Learning

  • Adobe Developer Connection
  • Adobe TV
  • Training and certification
  • Forums
  • Design Center

Ways to buy

  • For personal and home office
  • For students, educators, and staff
  • For small and medium businesses
  • For businesses, schools, and government
  • Special offers

Downloads

  • Adobe Reader
  • Adobe Flash Player
  • Adobe AIR
  • Adobe Shockwave Player

Company

  • News room
  • Partner programs
  • Corporate social responsibility
  • Career opportunities
  • Investor Relations
  • Events
  • Legal
  • Security
  • Contact Adobe
Choose your region United States (Change)
Choose your region Close

North America

Europe, Middle East and Africa

Asia Pacific

  • Canada - English
  • Canada - Français
  • Latinoamérica
  • México
  • United States

South America

  • Brasil
  • Africa - English
  • Österreich - Deutsch
  • Belgium - English
  • Belgique - Français
  • België - Nederlands
  • България
  • Hrvatska
  • Česká republika
  • Danmark
  • Eastern Europe - English
  • Eesti
  • Suomi
  • France
  • Deutschland
  • Magyarország
  • Ireland
  • Israel - English
  • ישראל - עברית
  • Italia
  • Latvija
  • Lietuva
  • Luxembourg - Deutsch
  • Luxembourg - English
  • Luxembourg - Français
  • الشرق الأوسط وشمال أفريقيا - اللغة العربية
  • Middle East and North Africa - English
  • Moyen-Orient et Afrique du Nord - Français
  • Nederland
  • Norge
  • Polska
  • Portugal
  • România
  • Россия
  • Srbija
  • Slovensko
  • Slovenija
  • España
  • Sverige
  • Schweiz - Deutsch
  • Suisse - Français
  • Svizzera - Italiano
  • Türkiye
  • Україна
  • United Kingdom
  • Australia
  • 中国
  • 中國香港特別行政區
  • Hong Kong S.A.R. of China
  • India - English
  • 日本
  • 한국
  • New Zealand
  • 台灣

Southeast Asia

  • Includes Indonesia, Malaysia, Philippines, Singapore, Thailand, and Vietnam - English

Copyright © 2012 Adobe Systems Incorporated. All rights reserved.

Terms of Use | Privacy Policy and Cookies (Updated)

Ad Choices

Reviewed by TRUSTe: site privacy statement