ADOBE FLEX BUILDER 3
Using Adobe Flex Builder 3
192
Creating an application that uses the generated proxy code
You can use MXML tags or ActionScript to call a web service. Equivalent MXML-centric and ActionScript-centric
applications use an address book web service that exposes the following operations:
• AddEntry lets you store someone's address.
• FindEntry lets you retrieve the address when you provide the person’s name.
The AddEntry operation takes an Entry object as input and returns nothing. The FindEntry operation takes a string
as input and returns an Entry object.
These sample applications demonstrate the following concepts for working with the code that Flex Builder generated
from the WSDL document:
• You can call a web service operation directly, as the following example shows:
myWebService.callOperation(parameters)
• The parameters passed to the web service operations are strongly typed and reflect the types that are described
in the WSDL document.
• The generated code includes event listeners that are specific to each operation; these listeners return strongly
typed results.
The MXML and ActionScript address book applications both use the following generated ActionScript classes:
Calling a service with MXML
For an MXML-centric application, you create an instance of the web service in an MXML tag, as the following code
snippet shows. Note that the application uses a custom namespace, ws; this namespace is declared as
xmlns:ws="com.adobe.*" in the <mx:Application> tag.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
xmlns:ws="com.adobe.*">
...
<!-- This is how we create an instance of the AddressBookService generated class.-->
<ws:AddressBookService id="myWebService">
<!-- We need to specify the request variables that are passed to the corresponding
operations. -->
<ws:addEntry_request_var>
Generated file Description
BaseAddressBookService.as A base implementation of the web service. This class contains the internal code that maps the operations
from the WSDL file to Flex WSDLOperation instances and sets the corresponding parameters.
IAddressBookService.as The service interface that defines all of the methods that users can access.
AddressBookService.as The concrete web service implementation.
BaseAddressBookService-
Schema.as
The XSD schema of the web service as an ActionScript custom type.
FindEntryResultEvent.as A strongly typed event type object for the FindEntry operation. For each web service operation, Flex
Builder generates a strongly typed event type class. You can use these classes to benefit from strongly
typed results.
AddEntry_request.as A request wrapper class for the AddEntry operation with the parameters as members. The request object
is intended for use with the MXML tag syntax.
FindEntry_request.as A request wrapper class for the FindEntry operation with the parameters as members. The request object
is intended for use with the MXML tag syntax.
Entry.as For each complex type defined in the WSDL file, Flex Builder generates a class with the same name as the
complex type or with the same name as the enclosing element.
ADOBE FLEX BUILDER 3
Using Adobe Flex Builder 3
193
<!-- The addEntry operation has one input parameter. This parameter's type is
Entry. -->
<ws:AddEntry_request>
<ws:param0>
<ws:Entry>
<!-- We bind each of the members of an Entry object to the
corresponding text input field.-->
<ws:name>{tiNameInput.text}</ws:name>
<ws:city>{tiCityInput.text}</ws:city>
<ws:street>{tiStreetInput.text}</ws:street>
<ws:state>{tiStateInput.text}</ws:state>
<ws:postalCode>{tiPostalCodeInput.text}</ws:postalCode>
</ws:Entry>
</ws:param0>
</ws:AddEntry_request>
</ws:addEntry_request_var>
<!-- The findEntry operation has one input parameter of the String type. -->
<ws:findEntry_request_var>
<!-- We bind the corresponding text input field to the operation's input
parameter.
Since the operation's input parameter has a simple type, you can use the
following syntax to do the data binding.
Alternatively you could do:
<ws:FindEntry_request>
<ws:param0>{tiSearch.text}</ws:param0>
</ws:FindEntry_request>
-->
<ws:FindEntry_request param0="{tiSearch.text}">
</ws:FindEntry_request>
</ws:findEntry_request_var>
</ws:AddressBookService>
...
On the click event for the Add entry button, call the addEntry_send() method to pass the request to the service, as
the following code snippet shows:
...
<mx:Button label="Add entry" labelPlacement="top" click="myWebService.addEntry_send();
clearInputFields()"/>
...
On the click event for the Find entry button, call the findEntry_send() method to pass the request to the service,
as the following code snippet shows:
...
<mx:Button label="Add entry" labelPlacement="top" click="myWebService.addEntry_send();
clearInputFields()"/>
...
In a Form control, bind the results of the findEntry operation to Form fields:
...
<mx:HBox id="hbResults" x="10" y="70" width="100%" verticalAlign="middle"
borderStyle="solid" visible="true">
<mx:Label text="Results:"/>
<!-- In the form that we use to display the data that is returned by the
web service, we bind each
member of the last result returned for the findEntry operation to
its corresponding text control. -->
<mx:Form width="293" height="181" borderStyle="solid">
<mx:FormItem label="Name">
Get ADOBE® FLEX® BUILDER™ 3: USING ADOBE FLEX BUILDER 3 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.