用WebORB实现flex + .net后台的Remoting
生活随笔
收集整理的這篇文章主要介紹了
用WebORB实现flex + .net后台的Remoting
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
實現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="*" path="weborb.aspx" type="Weborb.ORBHttpHandler"/>
????? <add verb="*" path="codegen.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.0
eclipse flex builder
1.下載WebORB,并安裝
2.新建asp.net工程Flat
copy WebORB工程目錄下的文件(我是安裝在:C:\Inetpub\wwwroot\weborb30):
weborb.config? 拷貝到根目錄
diagnostics.aspx? 拷貝到根目錄
weborb.dll? 拷貝到App_WebReferences目錄
3.引用weborb.dll到flat項目
4.修改flat項目的web.config文件,增加如下配置:
<httpHandlers>
????? <add verb="*" path="weborb.aspx" type="Weborb.ORBHttpHandler"/>
????? <add verb="*" path="codegen.aspx" type= "Weborb.Management.CodeGen.CodegeneratorHttpHandler"/>
</httpHandlers>
5.copy WEB-INF目錄下所有文件到 flat項目目錄下,可以隨意指定,但flex 項目中必須引用這個目錄,我這里copy到: E:\wwwroot\FlexDataCenter\WEB-INF\flex
6.新建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?的摘要說明
///?</summary>
public?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 id="my-amf" class="mx.messaging.channels.AMFChannel">
??????????? <endpoint uri="weborb.aspx" class="flex.messaging.endpoints.AMFEndpoint"/>
??????????? <properties>
??????????????? <polling-enabled>false</polling-enabled>
??????????? </properties>
</channel-definition>
這個配置指定 id是my-amf的remote請求都映射到當前站點的weborb.aspx,然后交由weborb.aspx的 httphandle處理程序處理
9.修改HelloNet項目的Build Path和debug,run path?: E:\wwwroot\FlexDataCenter\Flex (這是flat站點的目錄)
在flex application文件中增加代碼:
<?xml?version="1.0"?encoding="utf-8"?>
<mx:Application?xmlns:mx="http://www.adobe.com/2006/mxml"?layout="horizontal"
????xmlns="http://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?label="test?remote"?click="compinfo.Compute(1,4);">
????????
????</mx:Button>
????<mx:RemoteObject?id="compinfo"?destination="GenericDestination"?
?????????????????source="ComputeService"??
?????????????????showBusyCursor="true"?>
???????????<mx:method?name="Compute"?result="getComputerInfoHandler(event)"?fault="getFaultHandler(event);"/>
</mx:RemoteObject>?
</mx:Application>
注意:RemoteObject對象 的destination表示欲調用的后臺,都在remoting-config.xml配置文件中定義:
<destination id="GenericDestination">
??????? <properties>
??????????? <source>*</source>
??????? </properties>
??? </destination>
由.NET server端解析
采用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="*" path="weborb.aspx" type="Weborb.ORBHttpHandler"/>
????? <add verb="*" path="codegen.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.0
eclipse flex builder
1.下載WebORB,并安裝
2.新建asp.net工程Flat
copy WebORB工程目錄下的文件(我是安裝在:C:\Inetpub\wwwroot\weborb30):
weborb.config? 拷貝到根目錄
diagnostics.aspx? 拷貝到根目錄
weborb.dll? 拷貝到App_WebReferences目錄
3.引用weborb.dll到flat項目
4.修改flat項目的web.config文件,增加如下配置:
<httpHandlers>
????? <add verb="*" path="weborb.aspx" type="Weborb.ORBHttpHandler"/>
????? <add verb="*" path="codegen.aspx" type= "Weborb.Management.CodeGen.CodegeneratorHttpHandler"/>
</httpHandlers>
5.copy WEB-INF目錄下所有文件到 flat項目目錄下,可以隨意指定,但flex 項目中必須引用這個目錄,我這里copy到: E:\wwwroot\FlexDataCenter\WEB-INF\flex
6.新建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?的摘要說明
///?</summary>
public?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 id="my-amf" class="mx.messaging.channels.AMFChannel">
??????????? <endpoint uri="weborb.aspx" class="flex.messaging.endpoints.AMFEndpoint"/>
??????????? <properties>
??????????????? <polling-enabled>false</polling-enabled>
??????????? </properties>
</channel-definition>
這個配置指定 id是my-amf的remote請求都映射到當前站點的weborb.aspx,然后交由weborb.aspx的 httphandle處理程序處理
9.修改HelloNet項目的Build Path和debug,run path?: E:\wwwroot\FlexDataCenter\Flex (這是flat站點的目錄)
在flex application文件中增加代碼:
<?xml?version="1.0"?encoding="utf-8"?>
<mx:Application?xmlns:mx="http://www.adobe.com/2006/mxml"?layout="horizontal"
????xmlns="http://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?label="test?remote"?click="compinfo.Compute(1,4);">
????????
????</mx:Button>
????<mx:RemoteObject?id="compinfo"?destination="GenericDestination"?
?????????????????source="ComputeService"??
?????????????????showBusyCursor="true"?>
???????????<mx:method?name="Compute"?result="getComputerInfoHandler(event)"?fault="getFaultHandler(event);"/>
</mx:RemoteObject>?
</mx:Application>
注意:RemoteObject對象 的destination表示欲調用的后臺,都在remoting-config.xml配置文件中定義:
<destination id="GenericDestination">
??????? <properties>
??????????? <source>*</source>
??????? </properties>
??? </destination>
由.NET server端解析
轉載于:https://www.cnblogs.com/0000/archive/2009/08/14/1546364.html
總結
以上是生活随笔為你收集整理的用WebORB实现flex + .net后台的Remoting的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: -bash: ulimit: pipe
- 下一篇: Java异常处理机制很有意思