I' trying to isolate a webservice in its own class, and I plan to add separate classes to each webmethod there is in the webservice. So far, this is what I've got. And it works, I have this feeling tickling that I've missed something. (Except for the invisible variable declarations down here, I didn't want to clog the page).
The following is my webservice instatiation class and its fault handler.
public class CfdWS
{
[Bindable]
private var model:ModelLocator = ModelLocator.getInstance();
public function loadWebService():WebService{
var webService : WebService = new WebService();
webService.wsdl = model.configXML.cfdwsWSDL;
webService.addEventListener(FaultEvent.FAULT, onWebServiceFault);
webService.loadWSDL();
return webService;
}
private function onWebServiceFault(event:FaultEvent):void{
var fault: Fault = event.fault;
var message:String = "\ncodigo: " + fault.faultCode;
message += "\nDetalle: " + fault.faultDetail;
Alert.show("Error de webservice:" + message);
}
}
}
The following is my webservice method call class. I have written only what I think is the essential code for the question.
public class GeneratePDF extends CfdWS{
public function generatePDF():void{
webService = loadWebService();
webService.addEventListener(LoadEvent.LOAD, doGeneratePDF);
}
private function doGeneratePDF(event:LoadEvent):void{
webService.generatePDF.addEventListener(ResultEvent.RESULT, generatePDFResultHandler);
webService.generatePDF(pdfData);
}
private function generatePDFResultHandler (event:ResultEvent):void{
// After getting what I want, I remove the event listeners here.
}
}
Please don't murder me. This is my first attempt at "good practices" I've ever tried.
I'm trying to re-write an application that is already in production while on testing phase. Testing for the next version I mean.