Flex与.NET互操作(七):了解FluorineFx的环境配置(远程对象、网关、通道、目的地)...
注:本文內容原本計劃在上一篇《Flex與.NET互操作(六):Flex和.NET協同開發利器FluorineFx?》中寫出,考慮到寫在一起文章內容太長故分為兩篇。
?????Flex中的遠程對象訪問,也就是服務端提供一個遠程服務對象(RemotingService Object),在Flex客戶端通過相應的訪問技術去調用遠程對象的過程。
?????在本系列文章的前面幾篇文章中所介紹的訪問Webservice的方法,也就是一種遠程對象方法,只不過他是基于WEB服務(WebServie)的遠程訪問,不是基于遠程對象(Remoting Object)的的遠程訪問。要想直接實現基于對象的遠程訪問是比較麻煩的,然后FluorineFx則專門為我們提供了該功能,通過FluorineFx的核心庫來開發遠程對象(Remoting Object)服務,具體是怎么實現的呢?FluorineFx要求為遠程對象提供[RemotingService]標記來提供遠程對象服務,看看下面的RemotingServiceAttribute的詳細定義:
1?[AttributeUsage(AttributeTargets.Class,?AllowMultiple?=false)]2?publicsealedclassRemotingServiceAttribute?:?Attribute3?{4?publicRemotingServiceAttribute();5?publicRemotingServiceAttribute(stringserviceName);6?}?????從上一篇文章中的示例代碼可以看出,使用.NET(c#)定義了一個Sample的遠程對象服務類,并為其指定了[RemotingService],詳細如下:
1?[RemotingService("Fluorine?sample?service")]2?publicclassSample3?{4?publicSample()5?{6?}7?8?publicstringEcho(stringtext)9?{10?return"Gateway?echo:?"+text;11?}12?}?????從上一篇文章中搭建FluorineFx與.NET的開發環境過程中就已經出現過Flex客戶端調用FluorineFx的遠程對象示例,下面我們在來看看這個示例:
1?<mx:RemoteObject?id="service"destination="fluorine"2?source="FlexDotNet.ServiceLibrary.Sample">3?<mx:method?name="Echo"result="onResult(event)">4?</mx:method>5?</mx:RemoteObject> 1?<mx:Script>2?<![CDATA[3?import?mx.rpc.events.ResultEvent;4?internalfunction?onClick():void5?{6?service.Echo(txtInput.text);7?}8?9?internalfunction?onResult(evt:ResultEvent):void10?{11?txtResult.text?=evt.result.toString();12?}13?]]>14?</mx:Script>?????如上可實現遠程對象訪問,通過Flex的非可視化組件<mx:RemoteObject>進行遠程對象連接。其中的source屬性指定遠程對象,格式為全限定名(命名空間+類名)。destination屬性是非常重要的,這決定了Flex客戶端是否可以正確的訪問到遠對象,相關配置如下:
1?<destination?id="fluorine">2?<properties>3?<source>*</source>4?</properties>5?</destination>?????在<mx:RemoteObject>組件內部使用<mx:Mothod>組件配置遠程對象中的方法,詳細見本文前面部分。要真實實現遠程對象訪問的核心是對象的適配器和連接通道:
1?<?xml?version="1.0"encoding="UTF-8"?>2?<service?id="remoting-service"3?class="flex.messaging.services.RemotingService"4?messageTypes="flex.messaging.messages.RemotingMessage">5?<adapters>6?<adapter-definition?id="dotnet"class="FluorineFx.Remoting.RemotingAdapter"default="true"/>7?</adapters>8?9?<default-channels>10?<channel?ref="my-amf"/>11?</default-channels>12?13?<destination?id="fluorine">14?<properties>15?<source>*</source>16?</properties>17?</destination>18?</service>?????實際開發中我們可以進行自定義通信通道,默認情況下是使用FluorineFx為我們提供的默認連接通道:
1?<channels>2?<channel-definition?id="my-amf"class="mx.messaging.channels.AMFChannel">3?<endpoint?uri="http://{server.name}:{server.port}/{context.root}/Gateway.aspx"class="flex.messaging.endpoints.AMFEndpoint"/>4?<properties>5?<!--<legacy-collection>true</legacy-collection>?-->6?</properties>7?</channel-definition>8?</channels> 與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的Flex与.NET互操作(七):了解FluorineFx的环境配置(远程对象、网关、通道、目的地)...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 微粒贷逾期5天了 会不会通知家人
- 下一篇: asp.net ajax控件工具集 Au