RemoteObjectInvoker

(This tag must be placed inside an <EventHandlers> tag or a <MessageHandlers> tag)

The RemoteObjectInvoker tag is used to create a Remote Object instance and call a method on the object created. To use this tag, you need to specify the same attributes you would when creating a remote object with the <mx:RemoteObject> tag. In addition, you need to specify what method to call. This tag will also accept all mx.rpc.remoting.RemoteObject tag attributes (with the exception of the "operations" property).

<RemoteObjectInvoker destination="YourDestination" source="path.to.your.service" method="methodToCall" arguments="{['argument1', 'argument2']}" />

The above example would be the same as doing the following:

<mx:RemoteObject id="myService" destination="ColdFusion" source="path.to.this.service" />
myService.methodToCall('argument1', 'argument2');

You would also need to either create event handlers for the server result and fault or create a Responder to handle them. That is not necessary when using the RemoteObjectInvoker tag because results and faults are handled by Mate. See section "Handling a service result or fault".

With this tag, you can also utilize an already created RemoteObject instance. This is useful when the same services are used by several EventHandlers blocks or several EventMaps.

Suppose you have a Remote Object tag (either in the event map itself or in a different file):

<mx:RemoteObject id="myService" destination="ColdFusion" source="path.to.this.service" />

You can call a method on that already created service as follows:

<RemoteObjectInvoker instance="{myService}" 
	method="methodToCall"
	arguments="{['argument1', 'argument2']}" />

Attributes

method

required

The method attribute specifies what function to call on the remote object instance.

arguments

If the remote method has arguments, you can pass them via the "arguments" attribute.

Suppose you have a RemoteObject method called getPhotos and it expects a user name and an album name as arguments. You can specify them with the arguments attribute:

<RemoteObjectInvoker
	destination="YourDestination" source="path.to.your.service"
	method="getPhotos"
	arguments="{['Tom','My Album']}" />

Note that the arguments attribute expects an array. Besides passing literal values, you can pass values coming from the event that triggered the list execution:

<RemoteObjectInvoker
	destination="YourDestination" source="path.to.your.service"
	method="getPhotos"
	arguments="{[event.userName, event.album]}"/>

This assumes that the event contained a userName property and an album property.

You can also pass the complete data or lastReturn as an argument depending on what your service expects.

<RemoteObjectInvoker
	destination="YourDestination" source="path.to.your.service"
	method="getPhotos"
	arguments="{data}"/>
<RemoteObjectInvoker
	destination="YourDestination" source="path.to.your.service"
	method="getPhotos" 
	arguments="{lastReturn}"/>

Of course you can use any combination of arguments:

<RemoteObjectInvoker
	destination="YourDestination" source="path.to.your.service"
	method="getPhotos"
	arguments="{[event.age, lastReturn, 'Tom']}"/>

instance

A RemoteObject instance

The instance attribute specifies the already created service instance to use to make the call. This attribute must be supplied using bindings because it needs to point to an already created object.

Suppose you have a RemoteObject already created:

<mx:RemoteObject id="myService" destination="ColdFusion" source="path.to.this.service" />

You can make a call to this service by using the RemoteObjectInvoker tag, with instance {myService}. Note that any property you need for your service must be defined in the RemoteObject tag.

<RemoteObjectInvoker instance="{myService}" />

debug

Boolean

Whether to show debugging information for this RemoteObject resultHandlers and faultHandlers. If true, Console output will show debugging information as those handlers run.

Inner tags

resultHandlers

A set of handlers to run when the server call returns a result. Inside this inner tag, you can use the same tags you would in the main body of an <EventHandlers> block, including other service calls.

faultHandlers

A set of handlers to run when the server call returns a fault. Inside this inner tag, you can use the same tags you would in the main body of an <EventHandlers>, including other service calls.

Handling a service result or fault

You can have a resultHandlers block and a faultHandlers block inside the tag to handle service results and faults.

<RemoteObjectInvoker destination="YourDestination" 
  	source="path.to.your.service"
	method="methodToCall"
	arguments="{['argument1', 'argument2']}">

	<resultHandlers>
		... this list executes when server returns results ...
	</resultHandlers>
	
	<faultHandlers>
		... this list executes when server returns an error ...
	</faultHandlers>

</RemoteObjectInvoker>

See "Handling a service result or fault" for more information.

9 responses so far

  1. Hi,

    I'm experimenting with converting a Cairngorm application over to Mate, not having much luck since I'm also very new to Cairngorm. However, i've hit a snag with SetCredentials()

    Is SetCredentials() supported by MATE on remote object calls? If it is, can you point me in the right direction please.

    Many thanks,

    Matt Law
  2. Whoops, here it is:
    http://mate.asfusion.com/api_docs/com/asfusion/mate/actions/builders/ServiceInvoker.html
  3. So there's no discussion about the source attribute. Is it required? If so what exactly is this? Does it have to subclass a certain class?

    Charlie
  4. Charlie,
    All the attributes not discussed here correspond to the RemoteObject tag (http://livedocs.adobe.com/flex/3/langref/mx/rpc/remoting/RemoteObject.html ), including source and destination. Whether it is required or not depends on what adapter you are using on the server.
  5. Is there any way to pass in named arguments? i.e. firstName='Tom'
  6. Jim,
    Usually, the Flash Remoting Gateway will take an object as named arguments when it is the only thing you sent (it may vary by AMF implementation I guess). If you are passing literal values, then it is as simple as:
    <RemoteObjectInvoker
       ...
       arguments="{{firstName: 'Tom', lastName: 'Smith'}}"/>

    If you need data from somewhere else, then you can construct the object before sending it:

    <ObjectBuilder generator="{Object}" cache="false">
    <Properties firstName="{event.name}" lastName="{event.lastName}" />
    </ObjectBuilder>

    <RemoteObjectInvoker
       ...
       arguments="{lastReturn}"/>
  7. Have to say, I've been dipping in and out of this for weeks now, and its suprisingly easy to remember and get back in to.

    With those changes you did for me, I've now got it working with .NET authentication, and the Cafe Townsend example was the perfect basis for me to built my try-out my new application.

    All in all, great stuff!! :)

    Many thanks.
  8. How can I concatenate an event property ie. event.name to the source attribute?
    I want to do:
    source = "path.to.{event.name}.cfc"

    Thanks
  9. Rob,
    You'll have to create the path elsewhere (ie: using MethodInvoker) and then use the properties tag inside the RemoteObjectInvoker:
    <properties>
    <Properties source="{lastReturn}" />
    </properties>

    Having said that, I am not 100% sure you can dynamically change the source. I'll have to verify it.

Leave a response

If you need help or want to comment on something not related to this page, please post in the forums. Thanks!