(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.
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.
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
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.
Did you also try having a <mx:WebService> instance instead of declaring the service within the tag? ie:
<WebServiceInvoker instance="{myService}" method="getPhotos" />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)?