• 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资料,周六晚上也没有好好休息,好长时间没有陪儿子好好玩了,明天还得要开会,希望这些心得能对朋友有些帮助。


  • 相关阅读:
    flume杀掉重启
    Tomcat访问日志浅析 (转)
    httpclient Accept-Encoding 乱码
    解决Maven报Plugin execution not covered by lifecycle configuration
    mahout基于Hadoop的CF代码分析(转)
    hadoop Mahout中相似度计算方法介绍(转)
    nginx配置文件结构,语法,配置命令解释
    nginx 中文和英文资料
    使用异步 I/O 大大提高应用程序的性能
    nginx AIO机制与sendfile机制
  • 原文地址:https://www.cnblogs.com/jssy/p/931773.html
Copyright © 2020-2023  润新知