SlideShare una empresa de Scribd logo
1 de 37
Flex4.5 实战课程
    数据交互与通信
           http://weibo.com/agilelife

                            2011.08.26
数据交互与通信

  Contents
                       1. Flex中的数据集合
                       2. XML
             数据表现形式
                       3. JSON
                       4. AMF

                       1. URLLoader
             数据交互与通信   2. HTTPService
                       3.WebService
                       4. RemoteObject
数据交互与通信

  Overview
数据交互与通信
  Data
Collection

             1. Flex中的数据集合
              Array     ArrayCollection
              XMLList   XMLListCollection
数据交互与通信
  Data
Collection
数据交互与通信
  Data
Collection


   private var nameArray:Array = ["jex", "kenny", "richard"];

   //或者 private var nameArrayCollection:ArrayCollection = new ArrayCollection(nameArray);

   private var nameArrayCollection:ArrayCollection = new ArrayCollection();
   nameArrayCollection.source = nameArray;
数据交互与通信

    XML   private var personXML:XML =
                                  <root>
                                             <person>
                                                      <firstName>jex</firstName>
                                                      <lastName>chan</lastName>
                                             </person>
                                             <person>
                                                      <firstName>kenny</firstName>
                                                      <lastName>yang</lastName>
                                             </person>
                                             <person>
                                                      <firstName>hafid</firstName>
                                                      <lastName>tang</lastName>
                                             </person>
                                  </root>;

          xmlListCollection = new XMLListCollection(personXML.person);
数据交互与通信

    XML


          Array     ArrayCollection
          XMLList   XMLListCollection

          区别何在?
数据交互与通信
  Data
Collection
数据交互与通信
          var dataXML:XML =
    XML
              <products>
                  <product id="001" name="苹果MC700CH">
                     <price>8988.00</price>
                     <quatity>20</quatity>
                 </product>
                 <product id="002" name="戴尔Inspiron 14R">
                     <price>4399.00</price>
                     <quatity>50</quatity>
                 </product>
                 <product id="003" name="索尼VPCS138EC">
                     <price>7699.00</price>
                     <quatity>45</quatity>
                 </product>
            </products>;
数据交互与通信

    XML


          var xml:XMLList = dataXML.product;
          trace(xml.toXMLString();



          以XMLList方式列出所有Production的信息
数据交互与通信

     XML



  var xml:XMLList = dataXML.product.(@name == "苹果MC700CH");


  var xml:XMLList = dataXML.product.(attribute("name")=="苹果MC700CH");


  得到name为“苹果MC700CH”这条Product
数据交互与通信

     XML


  var xml:XMLList = dataXML.product.(quatity == 50);


     得到quatity为50的Product信息

  var xml:XMLList = dataXML.product.(@id == "001" || quatity == 45);

     得到id为001或quatity为50的Product信息
数据交互与通信

    XML



     //等价于:var xml:XMLList = dataXML.product.price;
     var xml:XMLList = dataXML..price;


     获取所有产品的price
数据交互与通信

    JSON


           JSON: JavaScript Object Notation
           当前比较流行的一 轻量级数据交换格式
           JavaScript标准的一个子集
           在前端 发中常用
           使用简单但 活性高
数据交互与通信

    JSON              JSON三类表示方式

           1. 名称/值 集合
           {"firstName":"Jex", "lastName":"Chan", "age":34}

                                                              Ojbect
           2. 值的有序列表
           [{"firstName":"jex", "lastName":"chan"},
            {"fistName":"kenny", "lastName":"yang"},
            {"fistName":"hafid", "lastName":"tang"}]

                                                              Array
数据交互与通信

    JSON              JSON三类表示方式

           3. 混合使用前           形式
           {"persons":[
                          {"firstName":"jex", "lastName":"chan"},
                          {"fistName":"kenny", "lastName":"yang"},
                          {"fistName":"hafid", "lastName":"tang"}
                              ]}

                                                               Object
数据交互与通信

        JSON               在Flex程序中读取JSON
                           https://github.com/mikechambers/as3corelib

                  //JSON解码
                  JSON.decode(srcStr)
            (1)
                  //JSON编码
                  JSON.encode(srcObj);



       //小技巧:直接通过EnternalInterface调用JavaScript方法解析JSON字符串
 (2)   //var myObj:Object = ExternalInterface.call('eval', "("+jsonStr+")");
数据交互与通信

    AMF


   AMF: Action Message Format
   http://opensource.adobe.com/wiki/download/attachments/1114283/amf3_spec_05_05_08.pdf


    Adobe专属的一 二进制压缩格式
    分为AMF0和AMF3 个大的版本
    在前端 发中常用
    高效
数据交互与通信

    AMF




          http://www.jamesward.com/census
数据交互与通信

    AMF


          不同语言的AMF实现

          作为网 (AMF Gateway)
          ActionScript类型与其它语言类型的序列化与反序列化
Java       --- BlazeDS  Granite Data Service
数据交互与通信                           http://opensource.adobe.com/wiki/display/blazeds/BlazeDS
                                  http://www.graniteds.org/confluence/
ata Communication   Ruby       --- RubyAMF
                                  https://github.com/thillerson/rubyamf

                    .Net       --- FluorineFx
                                  http://www.fluorinefx.com/

                    Python     --- pyAMF  amfast
                                  http://pyamf.org/
                                  http://code.google.com/p/amfast/

                    PHP        --- phpAMF
                                  https://github.com/amfphp/amfphp-1.9

                    Node.JS    --- node-amf
                                  https://github.com/timwhitlock/node-amf

                    Objective-C --- cocoa-amf
                                   https://github.com/nesium/cocoa-amf

                    Erlang     --- erlang-amf
                                   http://github.com/mujaheed/erlang-amf

                    WebORB         http://www.themidnightcoders.com/products.html
数据交互与通信

ata Communication


                    访问服务器端服务
                    URLLoader
                    HTTPService
                    WebService
                    RemoteObject
                    Socket
数据交互与通信

  URLLoader


    URLLoader
     private function onClick():void {
     	 	 	 	 var urlLoader:URLLoader = new URLLoader();
     	 	 	 	 urlLoader.addEventListener(Event.COMPLETE, onLoadComplete);
     	 	 	 	 urlLoader.load(new URLRequest("../assets/person.xml"));
     	 	 	 }
     	 	 	
     	 	 	 private function onLoadComplete(evt:Event):void {
     	 	 	 	 trace(evt.target.data);
     	 	 	 }
数据交互与通信

      URLLoader


  利用URLLoader向服务端 Post数据 -- Flex端
var   loader:URLLoader = new URLLoader();
	 	   	 	 var request:URLRequest = new URLRequest("http://localhost:8080/jsp_flex/hello_flex.jsp");
	 	   	 	 loader.dataFormat = URLLoaderDataFormat.VARIABLES;
	 	   	 	 var params:URLVariables = new URLVariables();
	 	   	 	 params.userName = "JexChan";
	 	   	 	 params.address = "ChengDu";
	 	   	 	 request.data = params;
	 	   	 	 request.method = URLRequestMethod.POST;
	 	   	 	 loader.addEventListener(Event.COMPLETE, onLoadComplete);
	 	   	 	 loader.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
	 	   	 	 loader.load(request);
数据交互与通信

    URLLoader



  利用URLLoader向服务端 Post数据 -- JSP端
<%@page contentType="text/html;charset=gb2312" language="java" %>
<%
	 String name=request.getParameter("userName");
	 String address=request.getParameter("address");
	 out.println("Back from JSP: " + "userName= " + name + " address= " + address);
%>
数据交互与通信

   HTTPService



  利用HTTPService向服务端 Post数据 -- Flex端
//httpService = new HTTPService();
	 	 	 	 //httpService.destination = "http://localhost:8080/jsp_flex/hello_flex.jsp";
	 	 	 	 //httpService.method = "POST";
	 	 	 	 var params:Object = {};
	 	 	 	 params.userName = "JexChan";
	 	 	 	 params.address = "ChengDu";
	 	 	 	 httpService.addEventListener(ResultEvent.RESULT, onHTTPServiceResult);
	 	 	 	 httpService.addEventListener(FaultEvent.FAULT, onHTTPServiceFault);
	 	 	 	 httpService.send(params);
数据交互与通信

ata Communication




                    URLLoader与HTTPService的不同
数据交互与通信

  WebService




               简繁体转换Web服务
               http://www.webxml.com.cn/WebServices/TraditionalSimplifiedWebService.asmx?wsdl
数据交互与通信

   WebService

  利用WebService组件访问WebService
private function onClick():void {
	 	 	 	 webService = new WebService();
	 	 	 	 webService.wsdl = WSDL_URL;
	 	 	 	 webService.addEventListener(ResultEvent.RESULT, onWebServiceResult);
	 	 	 	 webService.addEventListener(FaultEvent.FAULT, onWebServiceFault);
	 	 	 	 webService.toTraditionalChinese.resultFormat = "object";
	 	 	 	
	 	 	 	 webService.loadWSDL(WSDL_URL);
	 	 	 	 webService.addEventListener(LoadEvent.LOAD, onWSDLLoad);
	 	 	 }
	 	 	
	 	 	 private function onWSDLLoad(evt:LoadEvent):void {
	 	 	 	 webService.toTraditionalChinese("Flex企业级应用最佳实践");
	 	 	 }
数据交互与通信

     AMF




           BlazeDS与LCDS在功能上的对比
           http://www.jexchen.com/?p=94



           Flex + BlazeDS + Java环境配置
           http://www.jexchen.com/?p=87
数据交互与通信

     AMF




           BlazeDS Builds       4.0.1.21287
           blazeds.war
           blazeds-spring.war
           samples.war
           samples-spring.war
数据交互与通信

     AMF


           配置AMF网关 endpoint
                          http://localhost:8080/hello/messagebroker/amf


           配置BlazeDS remoting-config.xml
           <destination id=”helloservice”>
           	 <properties>
           	 	 <source>com.jexchen.blazeds.HelloWorldService</source>
           	 </properties>
           </destination>
数据交互与通信

         AMF



 private function onCall():void {
 	 	 	 	 myService.sayHello(nameInput.text);
 }



 <fx:Declarations>
 	 	 <s:RemoteObject id="myService" destination="helloservice"
                 endpoint="http://localhost:8080/hello/messagebroker/amf" />
 </fx:Declarations>
数据交互与通信

     AMF


 扩展阅读及参考资源:

     BlazeDS 内置范例
     Spring Flex:
     http://www.springsource.org/spring-flex

     BlazeDS 30minute test drive:
     http://www.adobe.com/devnet/livecycle/articles/blazeds_testdrive.html

     Christophe Coenraets:
     http://coenraets.org/blog/
数据交互与通信

    Notes




            作 业 ~~
提问
Q&A



      谢谢〜~〜~
      微博: http://weibo.com/agilelife

Más contenido relacionado

La actualidad más candente

Mongo db技术分享
Mongo db技术分享Mongo db技术分享
Mongo db技术分享晓锋 陈
 
cfm to php training
cfm to php training cfm to php training
cfm to php training Chonpin HSU
 
Asp.net mvc 培训
Asp.net mvc 培训Asp.net mvc 培训
Asp.net mvc 培训lotusprince
 
技术交流 支付二代信息安全及其代收付实现
技术交流 支付二代信息安全及其代收付实现技术交流 支付二代信息安全及其代收付实现
技术交流 支付二代信息安全及其代收付实现Banned Li
 
PHP & MySQL 教學
PHP & MySQL 教學PHP & MySQL 教學
PHP & MySQL 教學Bo-Yi Wu
 
D2 如何发现前端性能问题
D2 如何发现前端性能问题D2 如何发现前端性能问题
D2 如何发现前端性能问题aoao
 
Row Set初步学习V1.1
Row Set初步学习V1.1Row Set初步学习V1.1
Row Set初步学习V1.1Zianed Hou
 

La actualidad más candente (7)

Mongo db技术分享
Mongo db技术分享Mongo db技术分享
Mongo db技术分享
 
cfm to php training
cfm to php training cfm to php training
cfm to php training
 
Asp.net mvc 培训
Asp.net mvc 培训Asp.net mvc 培训
Asp.net mvc 培训
 
技术交流 支付二代信息安全及其代收付实现
技术交流 支付二代信息安全及其代收付实现技术交流 支付二代信息安全及其代收付实现
技术交流 支付二代信息安全及其代收付实现
 
PHP & MySQL 教學
PHP & MySQL 教學PHP & MySQL 教學
PHP & MySQL 教學
 
D2 如何发现前端性能问题
D2 如何发现前端性能问题D2 如何发现前端性能问题
D2 如何发现前端性能问题
 
Row Set初步学习V1.1
Row Set初步学习V1.1Row Set初步学习V1.1
Row Set初步学习V1.1
 

Similar a Flex 4.5 action data communication

用JAX-RS和Jersey完成RESTful Web Services
用JAX-RS和Jersey完成RESTful Web Services用JAX-RS和Jersey完成RESTful Web Services
用JAX-RS和Jersey完成RESTful Web Servicesjavatwo2011
 
运维系统开发与Rails 3页面开发实践
运维系统开发与Rails 3页面开发实践运维系统开发与Rails 3页面开发实践
运维系统开发与Rails 3页面开发实践Li JianYe
 
PHP Coding Standard and 50+ Programming Skills
PHP Coding Standard and 50+ Programming SkillsPHP Coding Standard and 50+ Programming Skills
PHP Coding Standard and 50+ Programming SkillsHo Kim
 
從 Web Site 到 Web Application,從 Web Services 到 Mobile Services
從 Web Site 到 Web Application,從 Web Services 到 Mobile Services從 Web Site 到 Web Application,從 Web Services 到 Mobile Services
從 Web Site 到 Web Application,從 Web Services 到 Mobile ServicesKuo-Chun Su
 
Parse, cloud code 介紹
Parse, cloud code 介紹Parse, cloud code 介紹
Parse, cloud code 介紹wantingj
 
Open Api&Sip
Open Api&SipOpen Api&Sip
Open Api&Sipcenwenchu
 
钟志 第八期Web标准化交流会
钟志 第八期Web标准化交流会钟志 第八期Web标准化交流会
钟志 第八期Web标准化交流会Zhi Zhong
 
Ajax Transportation Methods
Ajax Transportation MethodsAjax Transportation Methods
Ajax Transportation Methodsyiditushe
 
Ria的强力后盾:rest+海量存储
Ria的强力后盾:rest+海量存储 Ria的强力后盾:rest+海量存储
Ria的强力后盾:rest+海量存储 zhen chen
 
Android resource-management
Android resource-managementAndroid resource-management
Android resource-managementLucas Xu
 
HTML5 介绍
HTML5 介绍HTML5 介绍
HTML5 介绍S S
 
HTML5概览
HTML5概览HTML5概览
HTML5概览Adam Lu
 
EventProxy introduction - JacksonTian
EventProxy introduction - JacksonTianEventProxy introduction - JacksonTian
EventProxy introduction - JacksonTianJackson Tian
 
Event proxy introduction
Event proxy introductionEvent proxy introduction
Event proxy introductionmysqlops
 
希望科技研发部变量命名及编码规范
希望科技研发部变量命名及编码规范希望科技研发部变量命名及编码规范
希望科技研发部变量命名及编码规范Hongjian Wang
 
六步教你学会简单Rmi
六步教你学会简单Rmi六步教你学会简单Rmi
六步教你学会简单Rmiyiditushe
 
Exam 98-375 HTML5 Application Development Fundamentals
Exam 98-375 HTML5 Application Development FundamentalsExam 98-375 HTML5 Application Development Fundamentals
Exam 98-375 HTML5 Application Development FundamentalsChieh Lin
 

Similar a Flex 4.5 action data communication (20)

用JAX-RS和Jersey完成RESTful Web Services
用JAX-RS和Jersey完成RESTful Web Services用JAX-RS和Jersey完成RESTful Web Services
用JAX-RS和Jersey完成RESTful Web Services
 
运维系统开发与Rails 3页面开发实践
运维系统开发与Rails 3页面开发实践运维系统开发与Rails 3页面开发实践
运维系统开发与Rails 3页面开发实践
 
PHP Coding Standard and 50+ Programming Skills
PHP Coding Standard and 50+ Programming SkillsPHP Coding Standard and 50+ Programming Skills
PHP Coding Standard and 50+ Programming Skills
 
從 Web Site 到 Web Application,從 Web Services 到 Mobile Services
從 Web Site 到 Web Application,從 Web Services 到 Mobile Services從 Web Site 到 Web Application,從 Web Services 到 Mobile Services
從 Web Site 到 Web Application,從 Web Services 到 Mobile Services
 
Parse, cloud code 介紹
Parse, cloud code 介紹Parse, cloud code 介紹
Parse, cloud code 介紹
 
Open Api&Sip
Open Api&SipOpen Api&Sip
Open Api&Sip
 
钟志 第八期Web标准化交流会
钟志 第八期Web标准化交流会钟志 第八期Web标准化交流会
钟志 第八期Web标准化交流会
 
Hadoop ecosystem
Hadoop ecosystemHadoop ecosystem
Hadoop ecosystem
 
Ajax Transportation Methods
Ajax Transportation MethodsAjax Transportation Methods
Ajax Transportation Methods
 
Ria的强力后盾:rest+海量存储
Ria的强力后盾:rest+海量存储 Ria的强力后盾:rest+海量存储
Ria的强力后盾:rest+海量存储
 
Android resource-management
Android resource-managementAndroid resource-management
Android resource-management
 
HTML5 介绍
HTML5 介绍HTML5 介绍
HTML5 介绍
 
HTML5概览
HTML5概览HTML5概览
HTML5概览
 
EventProxy introduction - JacksonTian
EventProxy introduction - JacksonTianEventProxy introduction - JacksonTian
EventProxy introduction - JacksonTian
 
Event proxy introduction
Event proxy introductionEvent proxy introduction
Event proxy introduction
 
希望科技研发部变量命名及编码规范
希望科技研发部变量命名及编码规范希望科技研发部变量命名及编码规范
希望科技研发部变量命名及编码规范
 
六步教你学会简单Rmi
六步教你学会简单Rmi六步教你学会简单Rmi
六步教你学会简单Rmi
 
Structs2簡介
Structs2簡介 Structs2簡介
Structs2簡介
 
Glider
GliderGlider
Glider
 
Exam 98-375 HTML5 Application Development Fundamentals
Exam 98-375 HTML5 Application Development FundamentalsExam 98-375 HTML5 Application Development Fundamentals
Exam 98-375 HTML5 Application Development Fundamentals
 

Flex 4.5 action data communication

  • 1. Flex4.5 实战课程 数据交互与通信 http://weibo.com/agilelife 2011.08.26
  • 2. 数据交互与通信 Contents 1. Flex中的数据集合 2. XML 数据表现形式 3. JSON 4. AMF 1. URLLoader 数据交互与通信 2. HTTPService 3.WebService 4. RemoteObject
  • 4. 数据交互与通信 Data Collection 1. Flex中的数据集合 Array ArrayCollection XMLList XMLListCollection
  • 6. 数据交互与通信 Data Collection private var nameArray:Array = ["jex", "kenny", "richard"]; //或者 private var nameArrayCollection:ArrayCollection = new ArrayCollection(nameArray); private var nameArrayCollection:ArrayCollection = new ArrayCollection(); nameArrayCollection.source = nameArray;
  • 7. 数据交互与通信 XML private var personXML:XML = <root> <person> <firstName>jex</firstName> <lastName>chan</lastName> </person> <person> <firstName>kenny</firstName> <lastName>yang</lastName> </person> <person> <firstName>hafid</firstName> <lastName>tang</lastName> </person> </root>; xmlListCollection = new XMLListCollection(personXML.person);
  • 8. 数据交互与通信 XML Array ArrayCollection XMLList XMLListCollection 区别何在?
  • 10. 数据交互与通信 var dataXML:XML = XML <products> <product id="001" name="苹果MC700CH"> <price>8988.00</price> <quatity>20</quatity> </product> <product id="002" name="戴尔Inspiron 14R"> <price>4399.00</price> <quatity>50</quatity> </product> <product id="003" name="索尼VPCS138EC"> <price>7699.00</price> <quatity>45</quatity> </product> </products>;
  • 11. 数据交互与通信 XML var xml:XMLList = dataXML.product; trace(xml.toXMLString(); 以XMLList方式列出所有Production的信息
  • 12. 数据交互与通信 XML var xml:XMLList = dataXML.product.(@name == "苹果MC700CH"); var xml:XMLList = dataXML.product.(attribute("name")=="苹果MC700CH"); 得到name为“苹果MC700CH”这条Product
  • 13. 数据交互与通信 XML var xml:XMLList = dataXML.product.(quatity == 50); 得到quatity为50的Product信息 var xml:XMLList = dataXML.product.(@id == "001" || quatity == 45); 得到id为001或quatity为50的Product信息
  • 14. 数据交互与通信 XML //等价于:var xml:XMLList = dataXML.product.price; var xml:XMLList = dataXML..price; 获取所有产品的price
  • 15. 数据交互与通信 JSON JSON: JavaScript Object Notation 当前比较流行的一 轻量级数据交换格式 JavaScript标准的一个子集 在前端 发中常用 使用简单但 活性高
  • 16. 数据交互与通信 JSON JSON三类表示方式 1. 名称/值 集合 {"firstName":"Jex", "lastName":"Chan", "age":34} Ojbect 2. 值的有序列表 [{"firstName":"jex", "lastName":"chan"}, {"fistName":"kenny", "lastName":"yang"}, {"fistName":"hafid", "lastName":"tang"}] Array
  • 17. 数据交互与通信 JSON JSON三类表示方式 3. 混合使用前 形式 {"persons":[ {"firstName":"jex", "lastName":"chan"}, {"fistName":"kenny", "lastName":"yang"}, {"fistName":"hafid", "lastName":"tang"} ]} Object
  • 18. 数据交互与通信 JSON 在Flex程序中读取JSON https://github.com/mikechambers/as3corelib //JSON解码 JSON.decode(srcStr) (1) //JSON编码 JSON.encode(srcObj); //小技巧:直接通过EnternalInterface调用JavaScript方法解析JSON字符串 (2) //var myObj:Object = ExternalInterface.call('eval', "("+jsonStr+")");
  • 19. 数据交互与通信 AMF AMF: Action Message Format http://opensource.adobe.com/wiki/download/attachments/1114283/amf3_spec_05_05_08.pdf Adobe专属的一 二进制压缩格式 分为AMF0和AMF3 个大的版本 在前端 发中常用 高效
  • 20. 数据交互与通信 AMF http://www.jamesward.com/census
  • 21. 数据交互与通信 AMF 不同语言的AMF实现 作为网 (AMF Gateway) ActionScript类型与其它语言类型的序列化与反序列化
  • 22. Java --- BlazeDS Granite Data Service 数据交互与通信 http://opensource.adobe.com/wiki/display/blazeds/BlazeDS http://www.graniteds.org/confluence/ ata Communication Ruby --- RubyAMF https://github.com/thillerson/rubyamf .Net --- FluorineFx http://www.fluorinefx.com/ Python --- pyAMF amfast http://pyamf.org/ http://code.google.com/p/amfast/ PHP --- phpAMF https://github.com/amfphp/amfphp-1.9 Node.JS --- node-amf https://github.com/timwhitlock/node-amf Objective-C --- cocoa-amf https://github.com/nesium/cocoa-amf Erlang --- erlang-amf http://github.com/mujaheed/erlang-amf WebORB http://www.themidnightcoders.com/products.html
  • 23. 数据交互与通信 ata Communication 访问服务器端服务 URLLoader HTTPService WebService RemoteObject Socket
  • 24. 数据交互与通信 URLLoader URLLoader private function onClick():void { var urlLoader:URLLoader = new URLLoader(); urlLoader.addEventListener(Event.COMPLETE, onLoadComplete); urlLoader.load(new URLRequest("../assets/person.xml")); } private function onLoadComplete(evt:Event):void { trace(evt.target.data); }
  • 25. 数据交互与通信 URLLoader 利用URLLoader向服务端 Post数据 -- Flex端 var loader:URLLoader = new URLLoader(); var request:URLRequest = new URLRequest("http://localhost:8080/jsp_flex/hello_flex.jsp"); loader.dataFormat = URLLoaderDataFormat.VARIABLES; var params:URLVariables = new URLVariables(); params.userName = "JexChan"; params.address = "ChengDu"; request.data = params; request.method = URLRequestMethod.POST; loader.addEventListener(Event.COMPLETE, onLoadComplete); loader.addEventListener(IOErrorEvent.IO_ERROR, onIOError); loader.load(request);
  • 26. 数据交互与通信 URLLoader 利用URLLoader向服务端 Post数据 -- JSP端 <%@page contentType="text/html;charset=gb2312" language="java" %> <% String name=request.getParameter("userName"); String address=request.getParameter("address"); out.println("Back from JSP: " + "userName= " + name + " address= " + address); %>
  • 27. 数据交互与通信 HTTPService 利用HTTPService向服务端 Post数据 -- Flex端 //httpService = new HTTPService(); //httpService.destination = "http://localhost:8080/jsp_flex/hello_flex.jsp"; //httpService.method = "POST"; var params:Object = {}; params.userName = "JexChan"; params.address = "ChengDu"; httpService.addEventListener(ResultEvent.RESULT, onHTTPServiceResult); httpService.addEventListener(FaultEvent.FAULT, onHTTPServiceFault); httpService.send(params);
  • 28. 数据交互与通信 ata Communication URLLoader与HTTPService的不同
  • 29. 数据交互与通信 WebService 简繁体转换Web服务 http://www.webxml.com.cn/WebServices/TraditionalSimplifiedWebService.asmx?wsdl
  • 30. 数据交互与通信 WebService 利用WebService组件访问WebService private function onClick():void { webService = new WebService(); webService.wsdl = WSDL_URL; webService.addEventListener(ResultEvent.RESULT, onWebServiceResult); webService.addEventListener(FaultEvent.FAULT, onWebServiceFault); webService.toTraditionalChinese.resultFormat = "object"; webService.loadWSDL(WSDL_URL); webService.addEventListener(LoadEvent.LOAD, onWSDLLoad); } private function onWSDLLoad(evt:LoadEvent):void { webService.toTraditionalChinese("Flex企业级应用最佳实践"); }
  • 31. 数据交互与通信 AMF BlazeDS与LCDS在功能上的对比 http://www.jexchen.com/?p=94 Flex + BlazeDS + Java环境配置 http://www.jexchen.com/?p=87
  • 32. 数据交互与通信 AMF BlazeDS Builds 4.0.1.21287 blazeds.war blazeds-spring.war samples.war samples-spring.war
  • 33. 数据交互与通信 AMF 配置AMF网关 endpoint http://localhost:8080/hello/messagebroker/amf 配置BlazeDS remoting-config.xml <destination id=”helloservice”> <properties> <source>com.jexchen.blazeds.HelloWorldService</source> </properties> </destination>
  • 34. 数据交互与通信 AMF private function onCall():void { myService.sayHello(nameInput.text); } <fx:Declarations> <s:RemoteObject id="myService" destination="helloservice" endpoint="http://localhost:8080/hello/messagebroker/amf" /> </fx:Declarations>
  • 35. 数据交互与通信 AMF 扩展阅读及参考资源: BlazeDS 内置范例 Spring Flex: http://www.springsource.org/spring-flex BlazeDS 30minute test drive: http://www.adobe.com/devnet/livecycle/articles/blazeds_testdrive.html Christophe Coenraets: http://coenraets.org/blog/
  • 36. 数据交互与通信 Notes 作 业 ~~
  • 37. 提问 Q&A 谢谢〜~〜~ 微博: http://weibo.com/agilelife

Notas del editor

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n