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.

24 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.
  10. For the sake of portability across different servers i choose not to user services-config.xml file, usually creating a custom channel using parameters from flashVars:

    var ch:ChannelSet = new ChannelSet();
    ch..addChannel(new AMFChannel('amfphp', parameters.gatewayUrl));

    then use it in the service, i've glazed upon mate source code and found channelSet property in ServiceInvoker, i guess this would be the place to change it with above.

    Now, what would be the "Mate" way of doing this ?
  11. ion,
    You can do that or set each attribute you need to be dynamic with the Properties inner tag:
    <code>
    <RemoteObjectInvoker ...>
    <Properties endpoint="{YOUR DYNAMIC GATEWAY URL}" />
    </RemoteObjectInvoker>
    </code>

    The drawback is that you have to do it in every RemoteObjectInvoker. A better way would be to change that in the RemoteObject instance, either changing the channel set or the specific properties. You could do that in many different ways: binding those values to some static variable in a Config.as class, which you would change on FlexEvent.INITIALIZE or pass the remoteobject instance to some class that sets the properties, etc.
    Ie:
    <mx:RemoteObject endpoint="{Config.endpoint}" .../>
  12. Laura, Thanks for this previous answer - I am not at a level where I can really follow these tips. I am working on finding the best solution to use pyAMF with Google App Engine in combination with Mate. The pyAMF site shows how to manually configure a remote object (because pyAMF does not support service-config.xml or remoting-config.xml) but I am not seeing how to combine this with Mate's remote object features. Here is the pyAMF link: http://pyamf.org/wiki/RemoteObjectConfig. Any information you could provide or sources for further reading would be greatly appreciated.
  13. Hi Greg,
    I am pretty sure that you can still use the RemoteObject tag, even if you can't use services-config.xml. I think the example they show would translate to:
    <code>
    <mx:RemoteObject id="service" endpoint="http://localhost:8080/services"; destination="EchoService" />

    <EventHandlers ...>
       <RemoteObjectInvoker instance="{service}" method="echo" arguments="{['Hello World']}">
          ...
       </RemoteObjectInvoker>
    </EventHandlers>
    </code>

    If that doesn't work, then you can always add the channel set to the remoteObject tag (though I don't think the ChannelSet adds any information you don't already have).
  14. Can you pass an object from the event as the argument? So for example, if i had an object in my event called MyObject and an object in my view called formObject, and before I dispatch my event i set event.MyObject = formObject can i use that in my event map for the event RemoteObjectInvoker arguments as arguments="{event.MyObject}"? It works if I do {event.MyObject.requestID} but if i leave out the property it does not pass anything.
  15. Kyle,
    As most of the examples show, what you are trying to do should work. Please double check if indeed you are not received anything (turn debugging on and check in the console).
  16. Hi Laura,
    In debugging I can see the object looks like it was passed:
    arguments="[object SearchCriteriaVO]"
    However Coldfusion says the required argument was not passed in. Whats really strange is that if I change my argument from event.searchCriteria to event.searchCriteria.request my debugging says:
    arguments="1"
    and Coldfusion recieves the data. It seems like there is some property I am not using that I should be, any ideas?
  17. Kyle,
    Whenever you pass a single argument to a CF service (and that argument is not an aliased object), then you'll receive all the properties of the object as single parameters. That is the default behavior of the Flex remoting gateway. Since none of the names of your properties match the name of the required argument, you get the error. I see that you are trying to pass a SearchCriteriaVO. Probably the aliasing is not working correctly (make sure you have a SearchCriteriaVO in the server and that their aliases match.

    PS: For this type of problems, I recommend you to head to the forums.
  18. Can you leave the arguments attribute off of the remote Object invoker tag and it still work?
  19. Lavon,
    Yes, if you don't specify any arguments, then the service call will not send any parameters, but the call will be made regardless.
  20. Hi,
    Actually I wanted to post this in the forum, but I just cannot get in. So I try here.

    I am looking at options to authenticate through Mate to a backend. I have created a method, but now I feel I want to use a more ChannelSet oriented way. It would be great if I could do something like this:

    &lt;ChannelSetInvoker username="event.username" password="event.password" method="login">
    &lt;resultHandlers>
    &lt;MethodInvoker generator="{AuthenticationManager}" method="storeAuthenticationDetails"
    arguments="{resultObject}"/>
    &lt;EventAnnouncer generator="{AuthenticationEvent}" type="{AuthenticationEvent.AUTHENTICATED}"/>
    &lt;/resultHandlers>
    &lt;faultHandlers>
    &lt;MethodInvoker generator="{AuthenticationManager}" method="storeAuthenticationProblem"
    arguments="{fault}"/>
    &lt;/faultHandlers>
    &lt;/ChannelSetInvoker>

    I have written some functions that can actually do just this, but now I want to use the normal event handlers from Mate. What do you think? Would that be handy? I was working on a patch, but I cannot get it to work without flex builder. Tried with the flex-maven plugin, but something seems to go wrong. You have my email if you want more info.

    thanks Jettro
  21. Sorry about the previous xml, this might be better<br />&lt;ChannelSetInvoker username=&quot;event.username&quot; password=&quot;event.password&quot; method=&quot;login&quot;&gt;<br /> &lt;resultHandlers&gt;<br /> &lt;<a href="MethodInvoker</a>">http://mate.asfusion.com/page/documentation/tags/methodinvoker">MethodInvoker</a>; generator=&quot;{AuthenticationManager}&quot; method=&quot;storeAuthenticationDetails&quot;<br /> arguments=&quot;{resultObject}&quot;/&gt;<br /> &lt;<a href="EventAnnouncer</a>">http://mate.asfusion.com/page/documentation/tags/eventannouncer">EventAnnouncer</a>; generator=&quot;{AuthenticationEvent}&quot; type=&quot;{AuthenticationEvent.AUTHENTICATED}&quot;/&gt;<br /> &lt;/resultHandlers&gt;<br /> &lt;faultHandlers&gt;<br /> &lt;<a href="MethodInvoker</a>">http://mate.asfusion.com/page/documentation/tags/methodinvoker">MethodInvoker</a>; generator=&quot;{AuthenticationManager}&quot; method=&quot;storeAuthenticationProblem&quot;<br /> arguments=&quot;{fault}&quot;/&gt;<br /> &lt;/faultHandlers&gt;<br />&lt;/ChannelSetInvoker&gt;
  22. Having trouble finding an example of the RemoteInvoker endPoint. I'm evaluating Mate for adoption by my team and I can't seem to make a amfphp connection. I've tried several variation without luck. My call is being made from an air project.<br />Also can you tell me what I need to do to use the flex debugger. I have enabled Mate's debugging, but all it does is trace the call and response. So basicly it's telling me I have a fault which I'm announcing, but it's not firing the responder in the view. So I have no idea what the fault is. Can I set break points in the remoteObjectInvoker chain? I must be missing something. <br /><br />Help,<br /><br />John
  23. John,&lt;br /&gt;The best you can do is to try to connect to your remote object using plain RemoteObject tag and handle the result and faults. Once you have that working and figure out the problem, start using Mate and its &lt;a href=&quot;<a rel="nofollow" href="http://mate.asfusion.com/page/documentation/tags/services/remoteobjectinvoker&quot;&gt;<a href="RemoteObjectInvoker</a>&lt;/a&gt">http://mate.asfusion.com/page/documentation/tags/services/remoteobjectinvoker&quot;&gt;<a">http://mate.asfusion.com/page/documentation/tags/services/remoteobjectinvoker">RemoteObjectInvoker</a>&lt;/a&gt">http://mate.asfusion.com/page/documentation/tags/services/remoteobjectinvoker&quot;&gt;<a href="RemoteObjectInvoker</a>&lt;/a&gt</a>">http://mate.asfusion.com/page/documentation/tags/services/remoteobjectinvoker">RemoteObjectInvoker</a>&lt;/a&gt</a>;; tag. Also see his tutorials and videos:&lt;br /&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;<a rel="nofollow" href="http://mate.asfusion.com/news/hello-world-video-tutorial&quot;&gt;http://mate.asfusion.com/news/hello-world-video-tutorial&lt;/a&gt">http://mate.asfusion.com/news/hello-world-video-tutorial&quot;&gt;http://mate.asfusion.com/news/hello-world-video-tutorial&lt;/a&gt</a>;;
  24. Laura,&lt;br /&gt;Thanks for you quick response. I have viewed the Hello world screencast. It requests that I use a services xml file. I want to skip that step and use the endpoint instead, but I'm not having luck finding a real example of that working. I'm having as much trouble finding a mxml remoteobject tag example. I can implement and connect with a channell in AS, but no luck with mxml. Can you point me in the direction of a working example of either your &lt;a href=&quot;<a rel="nofollow" href="http://mate.asfusion.com/page/documentation/tags/services/remoteobjectinvoker&quot;&gt;<a href="RemoteObjectInvoker</a>&lt;/a&gt">http://mate.asfusion.com/page/documentation/tags/services/remoteobjectinvoker&quot;&gt;<a">http://mate.asfusion.com/page/documentation/tags/services/remoteobjectinvoker">RemoteObjectInvoker</a>&lt;/a&gt">http://mate.asfusion.com/page/documentation/tags/services/remoteobjectinvoker&quot;&gt;<a href="RemoteObjectInvoker</a>&lt;/a&gt</a>">http://mate.asfusion.com/page/documentation/tags/services/remoteobjectinvoker">RemoteObjectInvoker</a>&lt;/a&gt</a>;; or the mx remoteObject with endpoint used in it?&lt;br /&gt;&lt;br /&gt;John

Leave a response

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

Leave this field empty