电视盒子做网站服务器,集团网站推广,新版新白娘子传奇小青最后和谁在一起了,临武县网站建设实现flex与后台通信最简单的方式是采用httpServic的方式#xff0c;或webservice。但这两种方式都是基于文本的传输#xff0c;传输效率低#xff0c;采用RemoteObject的方式#xff0c;传输的内容采用AMF3格式的二进制编码#xff0c;效率较高#xff0c;并且能实现远程…实现flex与后台通信最简单的方式是采用httpServic的方式或webservice。但这两种方式都是基于文本的传输传输效率低采用RemoteObject的方式传输的内容采用AMF3格式的二进制编码效率较高并且能实现远程对象调用代码的可读性和开发效率也会有所提高。WebORB是adobe官方推荐的实现flex与.NET后台实现 RemoteObject 的解决方案。目前WebORB完全免费WebORB的原理介绍1. 在Server端WebORB利用.NET 的HTTPHANDLE机制HttpHandle是一种在.NET程序里显示IIS中 ISAPI功能的机制我的理解是实际上就是一种分发机制预处理机制。类似功能的还有HttpModule比如可以将默认需要在网站系统第一次被访问的时候就初始化以后就不需要再改变的内容利用HTTPMODULE机制重载它的OnInit方法实现。比如使用WebORB需要在web.config文件中增加如下配置httpHandlers add verb* pathweborb.aspx typeWeborb.ORBHttpHandler/ add verb* pathcodegen.aspx type Weborb.Management.CodeGen.CodegeneratorHttpHandler//httpHandlers这段配置表示所有.aspx的http请求在被IIS分配给aspnet_wp.exe处理后 对于名称是weborb.aspx的请求都交由Weborb.ORBHttpHandler这个类来处理同理所有codegen.aspx页面的请求交由Weborb.Management.CodeGen.CodegeneratorHttpHandler处理。在Weborb.ORBHttpHandler类的内部首先解析http请求的内容根据flex的AMF3二进制格式解码然后根据解码后的信息通过.net的反射机制将远程调用的对象转换成.NET对象并调用client端指定的方法然后生成对应结果集 再编码成AMF3格式返回给客户的2. 在client端flex根据编译时指定的services-config.xml配置将RemoteObect调用时指定的destination转换成对应的url调用在调用时生成一个对应http请求将欲调用的类和方法按协议转换成http请求内容。使用WEBORB的方法.NET版本 .NET 2.0 VS2005开发环境flex 3.0eclipse flex builder1.下载WebORB并安装2.新建asp.net工程Flatcopy WebORB工程目录下的文件我是安装在C:\Inetpub\wwwroot\weborb30weborb.config 拷贝到根目录diagnostics.aspx 拷贝到根目录weborb.dll 拷贝到App_WebReferences目录3.引用weborb.dll到flat项目4.修改flat项目的web.config文件增加如下配置httpHandlers add verb* pathweborb.aspx typeWeborb.ORBHttpHandler/ add verb* pathcodegen.aspx type Weborb.Management.CodeGen.CodegeneratorHttpHandler//httpHandlers5.copy WEB-INF目录下所有文件到 flat项目目录下可以随意指定但flex 项目中必须引用这个目录我这里copy到 E:\wwwroot\FlexDataCenter\WEB-INF\flex6.新建cs文件添加如下代码using System;using System.Data;using System.Configuration;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;/**//// summary/// ComputeService 的摘要说明/// /summarypublic class ComputeService{ public ComputeService() { // // TODO: 在此处添加构造函数逻辑 // } public int Compute(int arg1, int arg2) { return arg1 arg2; }}Compute方法实现一个计算2个参数之和的功能。7.在eclipse中新建flex工程 HelloNet。8.修改HelloNet项目的编译属性为-locale en_US -services E:\wwwroot\FlexDataCenter\WEB-INF\flex\services-config.xml主要是需要制定-services 参数设定services配置文件的读取路径以便swf文件在使用RemoteObject时将对应的amf channel映射到相应的url这个非常重要默认的一个channel配置如下channel-definition idmy-amf classmx.messaging.channels.AMFChannel endpoint uriweborb.aspx classflex.messaging.endpoints.AMFEndpoint/ properties polling-enabledfalse/polling-enabled /properties/channel-definition这个配置指定 id是my-amf的remote请求都映射到当前站点的weborb.aspx然后交由weborb.aspx的 httphandle处理程序处理9.修改HelloNet项目的Build Path和debugrun path E:\wwwroot\FlexDataCenter\Flex 这是flat站点的目录在flex application文件中增加代码?xml version1.0 encodingutf-8?mx:Application xmlns:mxhttp://www.adobe.com/2006/mxml layouthorizontal xmlnshttp://www.degrafa.com/2007 mx:Script ![CDATA[ import mx.rpc.events.FaultEvent; import mx.controls.Alert; import mx.rpc.events.ResultEvent; import mx.collections.ArrayCollection; import mx.rpc.events.ResultEvent; private function getComputerInfoHandler(event : ResultEvent) : void{ Alert.show(event.result.toLocaleString()); } private function getFaultHandler( event : FaultEvent) : void{ Alert.show(fault); } ]] /mx:Script mx:Button labeltest remote clickcompinfo.Compute(1,4); /mx:Button mx:RemoteObject idcompinfo destinationGenericDestination sourceComputeService showBusyCursortrue mx:method nameCompute resultgetComputerInfoHandler(event) faultgetFaultHandler(event);//mx:RemoteObject /mx:Application注意RemoteObject对象 的destination表示欲调用的后台都在remoting-config.xml配置文件中定义destination idGenericDestination properties source*/source /properties /destination 由.NET server端解析 转载于:https://www.cnblogs.com/0000/archive/2009/08/14/1546364.html