Thanks for the blessing :) This is my first attempt at publicing code as well as blogging so I'm a bit uncertain about the etiquette, does and don'ts.
Anyway... When trying to create an example of the error handling, I discovered two things:
1. A bug in the call queue. I goofed but now it's corrected.
2. The service allways returned the full response xml. For the moment, I just stripped it so that the content of the Response is returned. The goal is of course to analyse the wsdl and return properly converted data types (strings as strings, ints as ints and complex types as Objects or complex types when the type is registered with a Class alias). This is a project for the future :)
So download the new zip.
...and here is the example:
Service creation:
================================
protected function createService():void {
service = new WebService();
service.addEventListener(LoadEvent.LOAD, onWsdlLoad);
service.addEventListener(FaultEvent.FAULT, onWsdlLoadError);
service.loadWsdl("http://tech.manmachine.se/WebService.asmx?wsdl");
}
protected function onWsdlLoad(event:LoadEvent):void {
trace("wsdl loaded");
}
protected function onWsdlLoadError(event:FaultEvent):void {
trace("wsdl load error: " + event.fault);
}
Service call:
================================
protected function callService():void {
/*
Method 1
Assign IResponder to the AsyncToken
This class implements IResponder
Result is sent to result function and fault is sent to fault function
*/
var token1:AsyncToken = service.Hello("World");
token1.addResponder(this);
/*
Method 2
Listen to events on the AsyncToken
*/
var token2:AsyncToken = service.HelloObject("World");
token2.addEventListener(ResultEvent.RESULT, onResult);
token2.addEventListener(FaultEvent.FAULT, onFault);
}
public function result(data:*):void {
trace("result: " + data);
}
public function fault(info:*):void {
var f:Fault = info as Fault;
trace("fault: " + f);
}
public function onResult(event:ResultEvent):void {
trace("onResult: " + event.result);
}
public function onFault(event:FaultEvent):void {
trace("onFault: " + event.fault);
}