1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="initWebService();">
<mx:Script>
<![CDATA[
import mx.rpc.events.InvokeEvent;
import mx.rpc.soap.SOAPFault;
import mx.messaging.messages.ErrorMessage;
import mx.effects.Sequence;
import mx.controls.List;
import mx.controls.TextArea;
import mx.controls.Spacer;
import mx.events.FlexEvent;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.rpc.soap.LoadEvent;
import mx.rpc.soap.WebService;
import mx.collections.ArrayCollection;
public var _webService:WebService; // web service
public var _webServiceLoaded:Boolean = false; // flag noting when wsdl has been loaded
public function initWebService():void {
// initializes webservice
if (!_webService) {
_webService = new WebService();
// assign wsdl url
_webService.wsdl = "http://localhost:8080/service?wsdl"; // WSDL url
// add listeners
_webService.addEventListener(LoadEvent.LOAD, load_listener);
_webService.addEventListener(ResultEvent.RESULT, result_listener);
_webService.addEventListener(FaultEvent.FAULT, fault_listener);
// load wsdl
_webService.loadWSDL();
}
}
public function callHelloWorld(eventObj:Event):void {
if (_webServiceLoaded) { // is wsdl is loaded
var user = new Dictionary();
user["USER"] = "admin";
user["PASSWORD"] = "admin";
var criteria = new Dictionary();
criteria["VENDOR_ID"] = new uint(3);
webService.getHelloWorld(user);
}
}
public function load_listener(event:LoadEvent):void {
_webServiceLoaded = true; // mark wsdl as loaded so we know we can use the web service
}
public function result_listener(event:ResultEvent):void {
status.text = event.result as String;
trace(event.result);
}
public function fault_listener(event:FaultEvent):void {
trace(event);
}
public function creationApplicationListener(event:FlexEvent):void {
trace(event);
}
]]>
</mx:Script>
<mx:Button x="155" y="73" click="callHelloWorld(event)" label="Button" width="295" height="27"/>
<mx:TextArea id="status" x="155" y="108" width="295" height="275"/>
</mx:Application> |
Partager