The Flex WebService component provides a operations property but this is set by the MXML compiler and contains only the operations listed in the
If you want to access an unknown webservice and list at runtime all available operations, you can parse the WSDL xml by yourself or, more easily, use the WSDL parser of the Flex SDK.
Here a small example that I will explain later:
<mx:Script>
<![CDATA[
import mx.rpc.soap.LoadEvent;
import mx.rpc.wsdl.WSDLOperation;protected function loadHandler(event:LoadEvent):void
{
if(event.wsdl) {
for each(var op:WSDLOperation in event.wsdl.getPort().binding.portType.operations()) {
trace(op.name);
}
}
}
]]>
</mx:Script><mx:WebService load="loadHandler(event)" useProxy="false"
wsdl="http://webservices.amazon.com/AWSECommerceService/AWSECommerceService.wsdl"/>
One of the events for the WebService component is the load event. As stated on the reference the wsdl property of the LoadEvent class contains the WSDL object of the webservice just loaded. I'm not sure if this property could be null but I prefer to add a control to avoid a null pointer exception.
Now we have a WSDL object, but this class is not included in Flex language reference, so let's take a look to its source:
[ExcludeClass]
/**
* Manages a WSDL top-level definitions element. WSDL definitions
* may contain imports to other WSDL definitions. Only SOAP bindings are
* supported.
*
* @private
*/
public class WSDL
Well, this class will neither show up in the docs nor in the Flex Builder intellisense. This could indicate that it can be not stable or it could change with any SDK update, so pay attention!
Digging in the source I found that the interesting part is in parseBinding. Here for every
to a WSDLPortType object. This portType is stored in a WSDLBinding object that is returned by this function. The parseBinding method is called by the method itself and in the parsePort method. parsePort is called by parseService that is in getService method. You can call getService directly or through getPort.
These two methods both accept a serviceName and a portName parameter, both optional. The WSDLBinding object is stored in a WSDLPort that you can access using the getPort method.
In this way you can build a dynamic client to access every WebService without the need to know its structure in advance.