Service proxy已經產生完畢,
本篇使用ActionScripts來呼叫Service,
以下是範例程式碼~
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="initApp()"> <mx:Script> <![CDATA[ import generated.webservices.*; import mx.rpc.events.FaultEvent; import mx.controls.Alert; public var ws:Service1; //宣告ws //application initial時會呼叫的程式 public function initApp():void { ws=new Service1(); //建立 Service1的 instance } //當User按下按鈕,呼叫的Function public function callHelloWorld(echo:String):void{ // 建立呼叫helloWorldEvent的Listener, // 有回應則呼叫handleEchoResult ws.addhelloWorldEventListener(handleEchoResult); //呼叫operation ws.helloWorld(echo); } //當呼叫operation後,有任何 Response時,Listener會呼叫本function public function handleEchoResult(event:HelloWorldResultEvent):void{ this.txt_result.text=event.result; //將結果傳給input_text } ]]> </mx:Script> <mx:TextInput x="82" y="55" id="txt_result"/> <mx:Button x="82" y="85" label="呼叫Service" id="btn_callService" click="{callHelloWorld('island123');}" /> </mx:Application> |