WebServiceInvoker

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

The WebServiceInvoker tag allows you to create a Web Service (mx.soap.WebService) in your handlers list and call a method on that web service, in one step. To use this tag, you need to specify its wsdl attribute that will determine the address of the webservice. You also need to specify the method to call. In addition to those two, this tag will accept all mx.rpc.soap.WebService tag attributes (with the exception of xmlSpecialCharsFilter and operations).

<WebServiceInvoker
	wsdl="/myservices/myService.cfc?wsdl"
	method="serverMethodToCall"
	arguments="{['argument1', 'argument2']}" />

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

<mx:WebService id="myServiceInstance" wsdl="/myservices/myService.cfc?wsdl">

myServiceInstance.serverMethodToCall('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 WebServiceInvoker tag.

See section "Handling a service result or fault".

With this tag, you can also utilize an already created WebService instance. This is useful when the same services are used by several EventHandlers blocks or when using multiple event maps.

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

<mx:WebService id="myServiceInstance" wsdl="/myservices/myService.cfc?wsdl">

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

<WebServiceInvoker instance="{myService}" method="serverMethodToCall" />

Attributes

wsdl

required if no instance is specified

This attribute specifies the address for the WebService definition file. Refer to mx.rpc.soap.WebService documentation for more information.

method

required

The method attribute specifies what function to call on the web service instance.

arguments

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

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

<WebServiceInvoker
	wsdl="/myservices/myService.cfc?wsdl"
	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 of handlers to execute:

<WebServiceInvoker
	wsdl="/myservices/myService.cfc?wsdl"
	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.

<WebServiceInvoker
	wsdl="/myservices/myService.cfc?wsdl"
	method="getPhotos" 
	arguments="{data}"/>
<WebServiceInvoker
	wsdl="/myservices/myService.cfc?wsdl"
	method="getPhotos" 
	arguments="{lastReturn}"/>

Of course you can use any combination of arguments:

<WebServiceInvoker
	wsdl="/myservices/myService.cfc?wsdl"
	method="getPhotos" 
	arguments="{[event.age, lastReturn, 'Tom']}"/>

instance

A WebService 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 WebService already created:

<mx:WebService id="myServiceInstance" wsdl="/myservices/myService.cfc?wsdl">

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

<WebServiceInvoker instance="{myService}" method="getPhotos" />

debug

Boolean

Whether to show debugging information for this WebServiceInvoker 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

Just like all the "service invoker" tags, you can have a resultHandlers block and a faultHandlers block inside the tag to handle service results and faults.

<WebServiceInvoker
	wsdl="/myservices/myService.cfc?wsdl"
	method="serverMethodToCall"
	arguments="{['argument1', 'argument2']}" >

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

</WebServiceInvoker>

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

17 responses so far

  1. OK, how do we send the data back from a web service (ColdFusion cfc). None of your examples spell this one out. (It also is not obvious to me yet how I can look at the debug output of the web service return using Mate.)
  2. Hi John,
    You receive the data sent by the service using the eventHandlers inner tag (or are you asking how to send data from CF to Flex?). See page Handling a service result or fault. Also, most of the examples in the Examples page show how to get data coming from a service. The stock quotes example even uses a web service.
    Regarding your other question, see the "debug" attribute description.
  3. Hi!

    I've just started using Mate in a small project. Seems really nice for making reusable components.

    Using Fiddler I've discovered that the wsdl is loaded before every webservice call. Am I doing something wrong or is this intentional?

    Hakon
  4. Hi again!

    Another question: I have a web service which takes a complex object as input. Is it possible to use the webserviceinvoker to pass in such an object to the server?

    It seems that it can only handle simple arguments like {[event.username, event.password]}.

    If I pass in something like {[event.complexObject]} it seems that it will not get serialized properly.
  5. Hi Hakon,
    Did you also try having a <mx:WebService> instance instead of declaring the service within the tag? ie:
    <code>
    <WebServiceInvoker instance="{myService}" method="getPhotos" />
    </code>
  6. hakon,
    We followed the docs when calling the service, and they tell to call loadWSDL(). It seems though, that when they do that with the WebService tag, they do not call loadWSDL each time. So we'll have to make a check before attempting to load it.
    Regarding your other question, how do you normally pass that object (without Mate)?
  7. what about JSON support?
  8. Robert,
    The 3 service tags in Mate match the 3 Flex tags (RemoteObject, WebService, and HTTPService).
    JSON requests are normally made using the HTTPService tag, therefore you would use the HTTPServiceInvokere tag in Mate. You could then do the parsing in the resultHandlers using MethodInvoker.

    Having the http request and the parsing in one step would make a nice extension though.
  9. Hi, i have same problem with hakon, i've used WebServiceInvoker with instance from already created WebServices flex component, but it always reload WSDL every I call WebService method, Please give me suggestion to solve this
  10. Hi,
    all right, but wich argument can i pass trough the faultHandler for getting more information, whats getting wrong.
    similar to the faultEvent of Webservice and the FaultEvent from FlexFramework.
  11. Hi

    I want to be able to change the address of the wsdl at runtime. I am using the code below. I tried but each time I change it ... the web service calls are made to the initial url. I am tracing it.

    If I apply the same logic to the HTTPServiceInvoker it works fine. See code below

    Could it be that I cannot change the url of the wsdl with WebServiceInvoker ? Or do I missed something.

    And thanks for the GREAT work with Mate.


    <mx:WebService id="myWebService" wsdl="{myURLToWebService}" showBusyCursor="true" />
    <WebServiceInvoker
       instance="{myWebService}"
       method="{myMethod}"
       arguments="abc"
       debug="false">
       ... resultHandlers here
    </WebServiceInvoker>

    <mx:HTTPService id="myHTTPService" url="{myURLToHTTP}" resultFormat="e4x" />
    <HTTPServiceInvoker
       instance="{myHTTPService}">
       ... resultHandlers here
    </WebServiceInvoker>
  12. Is there a particular design reason why the operations attribute is not supported? I would like to send an operation w/ resultFormat and request attributes. Is there a workaround within the existing framework? Do you see it being supported in the future?
  13. Duncan,
    The best way is to declare everything you need, including operations in a WebService tag and use the instance attribute. (I am not sure about the request attributes, though)
    See: http://mate.asfusion.com/page/documentation/best-practices/service-invokers
  14. This is an example of a wsdl request element where param1 & param2 can occur 0 to many times and param3 is required.
    <xs:element name="webServiceRequest">
    <xs:complexType>
    <xs:sequence>
       <xs:choice>
          <xs:element maxOccurs="unbounded" minOccurs="0" ref="ols:param1"/>
          <xs:element maxOccurs="unbounded" minOccurs="0" ref="ols:param2"/>
       </xs:choice>
       <xs:element ref="ols:param3"/>
    </xs:sequence>
    </xs:complexType>
    </xs:element>

    How can i pass arguments to param2 & param3 of the web service request? The following webserviceinvoker tag is only passing the first argument to all the elements in the web service request?
    <WebServiceInvoker
       instance="myService"
       method="serviceMethodToCall"
       arguments="{['argument1', 'argument2']}" />
  15. How i can add headers for WebService?
  16. @Christophe : Did you found a solution ? I am facing the same problem ...
  17. Hi,

    I am having the same problem as Tracy. I tried passing a ValueObject with the same structure that is provided in the WSDL, but then when I got to pass it in the WebServiceInvoker arguments property the POST to the web service is not serialized properly and it will come back with a "interface is not recognized" or if I pass just one string parameter it will fill all of the inputs with the same value.

    Any ideas on how to get WebServiceInvoker to properly serialize output?

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