HTTPServiceInvoker

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

The HTTPServiceInvoker tag is used to create an HTTP Service instance and make a GET or POST request to that service. To use this tag, you need to specify the same attributes you would when creating an HTTP service with the <mx:HTTPService> tag (with the exception of xmlDecode, xmlEncode, and lastResult). In addition, you need to specify what method to call. This tag will also accept all mx.rpc.http.HTTPService tag attributes.

<HTTPServiceInvoker url="URLToCall" />

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

<mx:HTTPService id="myServiceInstance" url="http://www.example.com/services">

myServiceInstance.send();

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 HTTPServiceInvoker tag. See section "Handling a service result or fault".

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

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

<mx:HTTPService id="myService" url="http://www.example.com/services" />

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

<HTTPServiceInvoker instance="{myService}" />

Attributes

url

required if no instance is specified

This attribute specify the address to send the request. Refer to mx.rpc.http.HTTPService documentation for more information.

instance

An HTTPService 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 HTTPService already created:

<mx:HTTPService id="myService" url="http://www.example.com/services" />

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

<HTTPServiceInvoker instance="{myService}" />

debug

Boolean

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

Inner tags

Request

You can add variables to your HTTP request by using the Request inner tag. If using GET method, these variables will be sent as query string parameters. Otherwise, they will be added to the POST request.

As attributes of the Request tag, you specify the names of the variables you want to send and set the values of those variables by settings the value of the attributes.

Suppose you need to send a "photo_id" variable and a username variable with your request. Then you will specify:

<HTTPServiceInvoker instance="{myService}">
	<Request 
		photo_id="17"
		username="{event.username}" />
</HTTPServiceInvoker>

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.

<HTTPServiceInvoker url="URLToCall">

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

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

7 responses so far

  1. Is there a way to supply a hash to the Request tag? For example, with traditional mx:request, I can have:

    <mx:request>
    <person>
    <name> Joe </name>
    <age> 29 </age>
    </person>
    </mx:request>
  2. Or conversely, I could have httpSvc.send({person: {name: Joe} {age: 29}})
  3. Hi Justin,
    The HTTPServiceInvoker tag has a request attribute that works the same way as the <mx:request> as you showed in your first comment. I haven't tried it, but I think you should also be able to say:
    <HTTPServiceInvoker request="{person: {name: Joe} {age: 29}}" ...>

    Both ways would only work for literal values, however, but you would not be able to access what we call "Smart Objects", such as event, result, lastReturn. So you won't be able to supply event.age as a replacement for the value "29".

    To get around that, you could create your object before you pass it to the request using ObjectBuilder:

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

    <HTTPServiceInvoker>
        <Request person="{lastReturn}" />
    </HTTPServiceInvoker >


    If you need more "nesting", then you could have multiple ObjectBuilder tags, but to be honest, it would be messy. I would suggest you to use another class to do that, so you would use <MethodInvoker> to call a function "createMyPerson(name, age)" or similar, and then pass that with lastReturn to the Request tag. That would make it nicer if your object has many levels of nested properties.
  4. Laura,

    Thanks for the response; the information about the ObjectBuilder was very helpful. As it is, I ended up nesting the data within the event itself (converting the public property to a getter/setter with the business logic I needed) and that worked perfectly. I thought that it probably makes better sense to have the logic in the custom creation event than cluttering the EventMap.
  5. I think 'resultObject' should be mentioned somewhere on this page.
  6. First, great framework so far, but I still have to work out some techniques for bigger applications. I hope you have some recommendations or can add some stuff to the best practice section.

    I want to set some Request Parameters depending from a kind of Authorization Manager like you used in the cafeTownsend example.
    <HTTPServiceInvoker ...
    <Request username="{AuthorizationManager.user.name}" />

    However, I cannot access the manager from this scope, without using the ObjectBuilder in every HTTPServiceInvoker. I will have loads of them.

    Can you give a recommendation?

    The other problem is to create a Manager Object and setting values given via flashVars. I cannot access the Application from inside the EventMap.

    Thanks in advance!
    Simon
  7. I've try to use <mx request> tag inside the HTTPServiceInvoker tag but it cause an error to the compiler.I changed it to <mate request> but the problem still exist.How can i use the <mx request> tag in HTTPServiceInvoker as i use it in HTTPService ?

    My xml is like :
    <content name="/MainPageTemplate">
    <page name="Mobile Marketing Platform Keyword Manager" />
    <content localname="Nav" name="/TwoRowNav">
    <content localname="MSMNav" name="/:MSMNav">
    <content localname="MSMNav" name="/MSMNav">
    <Client>
    <clientId>2</clientId>
    <name>Velti Tech</name>
    <Product>
    <productId>6</productId>
    <clientId>2</clientId>
    <name>V-Phone</name>
    </Product>
    </Client>
    <Client>
    <clientId>4</clientId>
    <name>General Motors</name>
    <Product>
    <productId>8</productId>
    <clientId>4</clientId>
    <name>Saturn Vue</name>
    </Product>
    </Client>
    </content>
    </content>
    </content>
    </content>

    and i want to use clientId and productId

    Thanks

    Aris

Leave a response

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