Flex beta2+XFire开发实例 (三)
三、编写调用实例
1、设计界面
|
我是做得比较简单,有一个TextArea用来显示调用结果输出,一个Button用来调用服务的login方法。 |
2、代码编写
Webs1.mxml |
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init(event);"> <mx:Button x="207" y="192" label="getUserInfo" click="getUserInfo(event);"/> <mx:TextArea x="80" y="57" width="223" height="127" id="out"/> <mx:Script> <![CDATA[ import symis.business.service.UserManagerService; import symis.business.service.User; import mx.rpc.events.ResultEvent; import mx.rpc.AsyncToken; privatevar userManagerService:UserManagerService;
privatefunction init(e:Event):void{ userManagerService = new UserManagerService(); } privatefunction getUserInfo(e:Event):void{ var result:AsyncToken =null; if(userManagerService!=null) result =userManagerService.login(100,"hello"); if(result!=null) result.addEventListener("result",function(e:ResultEvent):void{ var user:User = e.result as User; out.text = "User Name:="+user.name+""n"; out.text +="age :="+user.age; }); } ]]> </mx:Script> </mx:Application> |
3、运行客户端
|
a) 初始化webservice privatefunction init(e:Event):void{ userManagerService = new UserManagerService(); } |
|
b) 调用webservice方法 privatefunction getUserInfo(e:Event):void{ var result:AsyncToken =null; if(userManagerService!=null) result =userManagerService.login(100,"hello"); if(result!=null) result.addEventListener("result",function(e:ResultEvent):void{ var user:User = e.result as User; out.text = "User Name:="+user.name+""n"; out.text +="age :="+user.age; }); } |
抽空写了一些WebService资料,周六晚上也没有好好休息,好长时间没有陪儿子好好玩了,明天还得要开会,希望这些心得能对朋友有些帮助。
posted on 2007-10-20 22:55 Bona shen 阅读(1320) 评论(1) 编辑 收藏 举报