Adobe® LiveCycle® Data Services ES 2.6 Developer Guide

Calling a service

Define the RemoteObject components in your client-side Flex application in MXML or ActionScript. The following example defines a RemoteObject component using both techniques:

<?xml version="1.0"?>
<!-- ds\rpc\ROInAS.mxml --> 
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
    creationComplete="useRemoteObject();">

    <mx:Script>
        <![CDATA[
            import mx.controls.Alert;
            import mx.rpc.remoting.mxml.RemoteObject;
            import mx.rpc.events.ResultEvent;
            import mx.rpc.events.FaultEvent;

            public var asService:RemoteObject;

            public function useRemoteObject():void {
                asService = new RemoteObject();
                asService.destination = "ro-catalog";
                asService.getList.addEventListener("result", getListResultHandler);
                asService.addEventListener("fault", faultHandler);
                asService.getList();
            }

            public function getListResultHandler(event:ResultEvent):void {
                 // Handle the result by accessing the event.result property.
            }

            public function faultHandler (event:FaultEvent):void {
             // Deal with event.fault.faultString, etc.
                Alert.show(event.fault.faultString, 'Error');
            }
        ]]>
    </mx:Script>

    <!-- Define the RemoteObject component in MXML. -->
    <mx:RemoteObject
        id="mxmlService"
        destination="ro-catalog"
        result="getListResultHandler(event);"
        fault="faultHandler(event);"/>
        
    <mx:Button label="MXML" click="mxmlService.getList();"/>       
    <mx:Button label="AS" click="asService.getList();"/>       

</mx:Application>

The destination specifies the Java class associated with the remote service. A Java class can expose multiple methods, corresponding to multiple operations. In this example, you directly call the getList() operation in response to a click event of a Button control.

Using the Operation class with the RemoteObject component

Because a single RemoteObject component can invoke multiple operations, the component requires a way to represent information specific to each operation. Therefore, for every operation, the component creates an mx.rpc.remoting.mxml.Operation object.

The name of the Operation object corresponds to the name of the operation. From the example shown in Calling a service, you access the Operation object that corresponds to the getList() operation by accessing the Operation object named getList, as the following code shows:

// The Operation object has the same name as the operation, without the trailing parentheses.
var myOP:Operation = mxmlService.getList;

The Operation object contains properties that you use to set characteristics of the operation, such as the arguments passed to the operation, and to hold any data returned by the operation. You access the returned data by using the Operation.lastResult property.

Invoke the operation by referencing it relative to the RemoteObject component, as the following example shows:

mxmlService.getList();

Alternatively, invoke an operation by calling the Operation.send() method, as the following example shows:

mxmlService.getList.send();

Defining multiple operations for the RemoteObject component

When a service defines multiple operations, you define multiple methods for the RemoteObject component and specify the attributes for each method, as the following example shows:

<mx:RemoteObject
    id="mxmlService"
    destination="ro-catalog"
    result="roResult(event);">
        <mx:method name="getList" fault="getLFault(event);"/>
        <mx:method name="updateList" fault="updateLFault(event);"/>
        <mx:method name="deleteListItem" fault="deleteLIFault(event);"/>
</mx:RemoteObject>

The name property of an <mx:method> tag must match one of the operation names. The RemoteObject component creates a separate Operation object for each operation.

Each operation can rely on the event handlers and characteristics defined by the RemoteObject component. However, the advantage of defining the methods separately is that each operation can specify its own event handlers, its own input parameters, and other characteristics. In this example, the RemoteObject component defines the result handler for all three operations, and each operation defines its own fault handler. For an example that defines input parameters, see Using parameter binding to pass parameters to the RemoteObject component.

Note: The Flex compiler defines the method property of the RemoteObject class; it does not correspond to an actual property of the RemoteObject class.

Setting the concurrency property

The concurrency property of the <mx:method> tag indicates how to handle multiple calls to the same method. By default, making a new request to an operation or method that is already executing does not impact the existing request.

The following values of the concurrency property are permitted:

  • multiple Existing requests are not impacted and the developer is responsible for ensuring the consistency of returned data by carefully managing the event stream. The default value is multiple.
  • single Making only one request at a time is allowed on the method; additional requests made while a request is outstanding are immediately faulted on the client and are not sent to the server.
  • last Making a request causes the client to ignore a result or fault for any current outstanding request. Only the result or fault for the most recent request is dispatched on the client. This can simplify event handling in the client application, but be careful to only use this mode when you can safely ignore results or faults for requests.

Note: The request referred to here is not the HTTP request. It is the method invocation request. If the transport between the client and server is HTTP, invocation requests are sent to the server within the body of HTTP requests and are processed on by the server. The last invocation request is not necessarily the last to be received by the server because in rare cases separate HTTP requests can travel over different routes through the network to the server, arriving in a different order than they were issued by the client.


 

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

Current page: http://livedocs.adobe.com/livecycle/8.2/programLC/programmer/lcds/rpc_remoteobject_4.html