In the previous article flex and. NET Interop (II): Based on WebService data Access (upper), the <mx:WebService> tags are introduced to access WebService. In fact, we can also dynamically access the Webservice,flex SDK programmatically to provide us with the WebService class.
Using the WebService class to access WebService actually means that the properties of the <mx:WebService> tag are represented by the properties of the class object, compared with the WebService analogy using the <mx:webservice > Label to be flexible. Let's look at how to connect and invoke a remote method programmatically:
1 internal function onClick():void
2 {
3 var service:WebService = new WebService();
4 service.loadWSDL ("http://localhost:1146/FlashFlexService.asmx?wsdl");
5 service.addEventListener (ResultEvent.RESULT,onResult);
6 service.addEventListener(FaultEvent.FAULT,onFault);
7 service.GetBook ();
8 }
Call the remote webservice directly through the LOADWSDL () method of the class object, dynamically assigning the related handler function to the class object, and then calling the remote WebService method as the label can.
1 internal function onResult(evt:ResultEvent):void
2 {
3 Alert.show(evt.result.Id);
4 }
5
6 internal function onFault(evt:FaultEvent):void
7 {
8 Alert.show (evt.fault.faultDetail.toString());
9 }
The call to access the remote WebService method programmatically using the WebService class is completed as above.