zoukankan      html  css  js  c++  java
  • Flex 调用webService

    今天手头没事,就学习下 Flex 调用webService的方法。本地测试OK  和大家分享下。

    ——————————————————————————————————————————————————————————

    1.首先需要编写webService服务。(此处略)

    2.Flex 中 新建一个 .mxml 文件

      在 <fx:Declarations> 节点中编写以下内容:

    1         <s:WebService id="myWeb" wsdl="http://localhost:8080/Demo/webService/demos?wsdl">
    2             <s:operation name="process" result="response(event)" fault="fault(event)" />
    3         </s:WebService>

    代码说明:
    <s:webService>  :  标签使您可以访问与 SOAP 兼容的 Web 服务的操作

                          id :  后面的代码会用到此名称。通过此名称来调用webService服务

                      wsdl :  自己编写的webService发布的地址

    <s:operation>    :  调用webService中方法

                    name :  调用 webService 方法名称  必须和webService中定义的一致

                    result :  声明结果处理程序

                     fault :   声明错误处理程序

    新建 <fx:Script> 节点 并插入以下内容:

     1     <fx:Script>
     2         <![CDATA[
     3             import mx.controls.Alert;
     4             import mx.rpc.events.FaultEvent;
     5             import mx.rpc.events.ResultEvent;
     6             
     7             public function getOrderFun():void{
     8                 myWeb.process.send(this.username.text);
     9             }
    10             
    11             public function response(e:ResultEvent):void{
    12                 this.responseText.text = e.result.toString();
    13             }
    14             
    15             public function fault(e:FaultEvent):void{
    16                 Alert.show(e.message.toString());
    17             }
    18         ]]>
    19     </fx:Script>

    代码说明:

    命令按钮 通过  方法  getOrderFun   来调用webService

    response 方法 是结果处理程序

    fault  方法 是错误处理程序

    编写 控件 代码 :

    1     <s:Label text="输入内容" x="50" y="75" />
    2     <s:TextInput id="username" x="118" y="71" />
    3     <s:Button id="button" x="255"  y="71" label="提交" click="getOrderFun()"/> 
    4     <s:TextInput id="responseText" x="118" y="117" />
    5     <s:Label text="结果信息" x="51" y="121" />


    代码描述:

    用户 通过在 文本框中输入数据  ,单击提交按钮后 ,在 responseText中 就可以显示 webService 提供的process 方法的返回值。

    此时  Flex 调用 webService 成功。。

    ——————————————————————————————————————————————————————————————

    注:

    本程序中 调用的webService中的process 方法非常简单,定义如下

    1 public String process(@WebParam(name = "testID") String testID);

    实现也很简单 如下:

    1     public String process(String ticketID) {
    2         return ticketID + "webService 返回信息";
    3     }
  • 相关阅读:
    Windows 7 Phone 文档数据库Rapid Repository正式发布
    Adobe展示HTML5动画制作IDE
    详解Android实现全屏正确方法
    qtform.com计划
    Adobe加速布局移动开发:Flash Builder+Flex+AIR+Catalyst
    预览:Visual Basic与C#中的异步语法
    Windows 7主题中的壁纸从哪里来?
    F#的编译器及标准库使用Apache 2.0协议开源(暂时还没有看到未来)
    开发者谈Symbian、iPhone、Android、MeeGo平台
    MeeGo 1.1发布
  • 原文地址:https://www.cnblogs.com/zhonghuazhi/p/3425891.html
Copyright © 2011-2022 走看看