Flex 开发gSOAP的客服端

来源:互联网 发布:语音王软件 编辑:程序博客网 时间:2024/05/16 06:11

     准备一个Flash builder 安装包,安装过程这里就不叙述了

     1打开这个工具,新建一个工程,换成设计视图,在设计视图中拖一个见面, 如图:

          

    2.内部代码稍作修改,大体如下:

<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
        xmlns:s="library://ns.adobe.com/flex/spark"
        xmlns:mx="library://ns.adobe.com/flex/mx" height="400"
        width="420" applicationComplete="windowedapplication1_applicationCompleteHandler(event)">
 
 <fx:Script>
  <![CDATA[
   import ServiceManage.WebService.GService;   
   import mx.controls.Alert;
   import mx.events.FlexEvent;
   import mx.rpc.events.FaultEvent;
   import mx.rpc.events.ResultEvent;
   import mx.rpc.soap.LoadEvent;
   import mx.rpc.soap.WebService;
   
   private var m_gSer:GService;
   
   private var m_webser:WebService;
   
   public function OnRes(res:ResultEvent):void
   {
    Alert.show("OnRes");
   }
   protected function btnLoadwsdl_clickHandler(event:MouseEvent):void
   {
    // TODO Auto-generated method stub
    m_webser.wsdl = "http://192.168.0.3:9999/ns.wsdl";
    
    m_webser.addEventListener(ResultEvent.RESULT, OnRes);
    //m_webser.addEventListener(ResultEvent.RESULT,
    m_webser.addEventListener(FaultEvent.FAULT, OnFault);
    
    m_webser.addEventListener(LoadEvent.LOAD, OnLoadWsdlSuccess);
    m_webser.loadWSDL();
   }
  
   protected function windowedapplication1_applicationCompleteHandler(event:FlexEvent):void
   {
    // TODO Auto-generated method stub
    //m_webser = GService.GetInstance();
    m_webser = new WebService;
    
    btnLoadwsdl_clickHandler(null);
   }
   
   /**
    * wsdl加载成功,服务初始化成功
    *
    * */
   public function OnLoadWsdlSuccess(e:LoadEvent):void
   {
    //m_gSer.removeEventListener(ResultEvent.RESULT ,OnLoadWsdlSuccess);
    //m_gSer.removeEventListener(FaultEvent.FAULT, OnLoadWsdlFault);
    trace("-------OnLoadWsdlSuccess--------");  
    Alert.show("OnLoadWsdlSuccess");
    txtName.text = "success";
   }
   
   /**
    *
    * wsdl失败处理函数
    *
    */
   public function OnFault(evt:FaultEvent):void
   {
    //m_gSer.removeEventListener(ResultEvent.RESULT, OnLoadWsdlSuccess);
    //m_gSer.removeEventListener(FaultEvent.FAULT, OnLoadWsdlFault);
    trace("-------OnLoadWsdlFault--------");
    Alert.show("OnLoadWsdlFault");
   }
   public function OnLoginSuccess(eve:ResultEvent):void
   {
    Alert.show(eve.result.toString());
   }
   public function OnLoginFault(eve:FaultEvent):void
   {
    Alert.show(eve.toString());
   }
   protected function btnLogin_clickHandler(event:MouseEvent):void
   {
    // TODO Auto-generated method stub
    m_webser.Login.addEventListener(ResultEvent.RESULT, OnLoginSuccess);
    m_webser.Login.addEventListener(FaultEvent.FAULT, OnLoginFault);
    m_webser.Login(txtName.text, txtPsw.text);
   }
   
   protected function btnCancel_clickHandler(event:MouseEvent):void
   {
    // TODO Auto-generated method stub
    close();
   }
   
  ]]>
 </fx:Script>
 
 <fx:Declarations>
  <!-- 将非可视元素(例如服务、值对象)放在此处 -->
 </fx:Declarations>
 <s:Button id="btnLoadwsdl" x="338" y="146" label="加载wsdl" click="btnLoadwsdl_clickHandler(event)"/>
 <s:Button id="btnLogin" x="102" y="117" label="登陆" click="btnLogin_clickHandler(event)"/>
 <s:Button id="btnCancel" x="207" y="118" label="取消" click="btnCancel_clickHandler(event)"/>
 <s:Label x="98" y="54" text="用户名:"/>
 <s:Label x="97" y="83" text="密    码:"/>
 <s:TextInput x="146" y="48" id="txtName"/>
 <s:TextInput x="146" y="78" id="txtPsw"/>
</s:WindowedApplication>

要说的是这两句

private var m_gSer:GService;

private var m_webser:WebService;
   申明了两个私有的变量,名字分别为m_gSer和m_webSer,类型分别为GServer 和 WebService,

他们分别是服务端的映射,就相当于使用服务端Server这个类!

   3.此客服端的登陆界面运行时,它会根据函数

protected function btnLoadwsdl_clickHandler(event:MouseEvent):void
{
// TODO Auto-generated method stub
m_webser.wsdl = "http://192.168.0.3:9999/ns.wsdl";

m_webser.addEventListener(ResultEvent.RESULT, OnRes);
//m_webser.addEventListener(ResultEvent.RESULT,
m_webser.addEventListener(FaultEvent.FAULT, OnFault);

m_webser.addEventListener(LoadEvent.LOAD, OnLoadWsdlSuccess);
m_webser.loadWSDL();
}
  中的m_webser.wsdl = "http://192.168.0.3:9999/ns.wsdl";自动加载服务端的wsdl 文件,成功与否都返回成功与否的信息。

   当返回成功信息时,我们输入数据库的用户名和密码,并返回登陆成功与否的信息。

 

上面的功能只是完成了加载和登陆功能,还可以对数据库进行 增、删、改、查等功能,如图:

       

                                                       (图一)

          

                                                              (图二)

 

          

                                                                          (图三)

              其内部功能和写法和登陆图的写法方法类似,这里就不在叙述。
原创粉丝点击