利用Fluorine實現(xiàn)Flex與.net的通訊(.net)
1、服務(wù)器端的搭建: (1)安裝FluorineFx,安裝完后在目錄中會有“Source”及“Samples”兩個文件夾,“Samples”文件夾中包含了一些在VS.Net環(huán)境中使用Fluorine的例子。“Source”文件夾中包含了有關(guān)Fluorine的源代碼。(代碼未具體去研究)
(2)安裝好Fluorine之后,系統(tǒng)自動在VS.Net 2008新建網(wǎng)站中增加一個模板:FluorineFx ASP.NET Web Application。選擇該模板,創(chuàng)建一個.NET網(wǎng)站。 ![]()
圖3.1 a)打開Visual Studio 2008,分別選擇 文件 -> 新建 -> 網(wǎng)站 c)運行項目,獲取.NET自帶服務(wù)器生成的端口,及網(wǎng)址,本項目中是 http://localhost:4166/FluorineTest/ (3)利用VS的模板進行創(chuàng)建后,系統(tǒng)會自動加載一些引用,以及創(chuàng)建相關(guān)文件,并進行簡單配置。創(chuàng)建完后的項目結(jié)構(gòu)如圖所示: 圖3.2 “Bin”中的Dll就是用Fluorine的源文件所生成的程序集,“Templates”是一些模板。“WEB-INF/flex”中包含了XML都是些配置文件。“Gateway.aspx”是個空頁面,其網(wǎng)頁地址就是Fluorine的網(wǎng)關(guān)地址。 2、客戶端的配置: 客戶端的配置有三種方法,一種是通過向?qū)碓O(shè)置參數(shù),從而創(chuàng)建Flex;另一種是通過指定services-config.xml配置文件來設(shè)置;第三種是利用第三方組件RemoteObjectAMF0來連接,這種方式就不用再去配置services-config.xml。(推薦用第三種方法) (1)向?qū)гO(shè)置方法: 步驟1. 新建Flex工程。選擇ColdFusion Flash Remoting。如圖3.3: 2. 配置服務(wù)器。Deployed to J2EE server。如圖3.4:
2)services-config.xml配置文件來設(shè)置
修改工程的屬性,如圖3.5: Additional compiler arguments”,設(shè)置services-config.xml配置文件的路徑,可以指向剛才建立的VS.Net項目中的“WEB-INF/flex”中的services-config.xml路徑。也可以將services-config.xml這個文件拷貝到調(diào)用文件的同級目錄中,然后如上面所設(shè)。
(3)利用第三方組件RemoteObjectAMF0來連接,這種方法講到時再進行介紹。
四、通信過程 1、在VS.Net中編寫數(shù)據(jù)處理類HelloWorld.cs文件(可以新建一個FluorineFx ServiceLibrary類庫文件,將所有的數(shù)據(jù)處理類放到庫中上,然后在網(wǎng)站中調(diào)用此類庫,這里就不創(chuàng)建了)。HelloWorld.cs文件的代碼如下所示: using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using FluorineFx; namespace FluorineHelloWorld { /// <summary> ///HelloWorld 的摘要說明 /// </summary> [RemotingService()] public class HelloWorld { public HelloWorld() { // //TODO: 在此處添加構(gòu)造函數(shù)邏輯 // } public string FromFluorine(string userName) { return "您好," + userName + "!此消息來自Fluorine Flash Remoting"; } } }
RemotingService屬性并不是必需的,不過使用該屬性,在配置了服務(wù)瀏覽器的Web應(yīng)用上可以通過Console.aspx查看遠程服務(wù)類文件,以及調(diào)用該服務(wù)的ActionScrip。例如可以在上頁類文件中設(shè)置斷點,然后將Console.aspx設(shè)置為起始頁,啟動項目。頁面會跳轉(zhuǎn)到Fluorine.aspx頁面,當(dāng)調(diào)用FromFluorine()函數(shù)時,就會中斷。下圖是對函數(shù)所進行的調(diào)用結(jié)果。
圖4.1 2、配置Flex工程中的services-config.xml。主要是設(shè)置這個endpoint屬性。讓其指向之前得到的網(wǎng)關(guān)地址,另外就是設(shè)置了“destination”。 <?xml version="1.0" encoding="UTF-8"?> <services-config> <services> <service id="remoting-service" class="flex.messaging.services.RemotingService" messageTypes="flex.messaging.messages.RemotingMessage"> <destination id="fluorine"> <channels> <channel ref="my-amf"/> </channels> <properties> <source>*</source> </properties> </destination> </service> </services> <channels> <channel-definition id="my-amf" class="mx.messaging.channels.AMFChannel"> <endpoint uri="http://localhost:4166/FluorineTest/Gateway.aspx" class="flex.messaging.endpoints.AMFEndpoint"/> </channel-definition> </channels> </services-config>
![]()
![]()
![]()
|
posted on 2010-11-12 11:22 aiaiwoo 閱讀(582) 評論(0) 編輯 收藏 所屬分類: AC3/FLEX