1.
下載 FluorineFx v1.0.0.15
http://www.fluorinefx.com/download.html
2.
安裝後,可以在 VS.NET 2005 中,使用相關的專案,
不過,下面要敘述的是,如何複製必要的檔案,就可以在既有的網站中,使用 Flex Remoting
3.
對於提供 service 的 dll 的部分:
3.1.
先在 Class Library 的專案中,加入 FluorineFx.dll 的參考,
3.2.
Class1.cs 原始檔:
using System;
using System.Collections.Generic;
using System.Text;
using FluorineFx;
namespace ServiceClsLib
{
[RemotingService]
public class Class1
{
public string hello(string who)
{
return "hello, " + who;
}
}
}
4.
網站專案的部分:
4.1.
加入以下參考:
* FluorineFx.dll
* FluorineFx.ServiceBrowser.dll
* 步驟三的 dll
4.2.
web.config 中加入 Fluorine 的 httpModule
<system.web> <httpModules> <add name="FluorineGateway" type="FluorineFx.FluorineGateway, FluorineFx"/> </httpModules> </system.web>
4.3.
放一個 Gateway.aspx,可以不加任何程式,但是一定要放,
想必是,主要工作還是由 httpModule 來處理,但是若沒有這個 gateway.aspx 的話,會因 404 錯誤而中斷,
4.4.
放一個 Console.aspx,負責導向至 Fluorine.aspx,
若你想直接連 Fluorine.aspx,也 OK,
5.
Flex client 的部分:
5.1.
準備 services-config.xml
<?xml version="1.0" encoding="utf-8" ?> <services-config> <services> <service-include file-path="remoting-config.xml" /> </services> <channels> <channel-definition id="my-amf" class="mx.messaging.channels.AMFChannel"> <endpoint uri="http://localhost:3000/Gateway.aspx" class="flex.messaging.endpoints.AMFEndpoint"/> </channel-definition> </channels> </services-config>
5.2.
準備 remoting-config.xml
<?xml version="1.0" encoding="UTF-8"?> <service id="remoting-service" class="flex.messaging.services.RemotingService" messageTypes="flex.messaging.messages.RemotingMessage"> <adapters> <adapter-definition id="dotnet" class="FluorineFx.Remoting.RemotingAdapter" default="true"/> </adapters> <default-channels> <channel ref="my-amf"/> </default-channels> <destination id="fluorine"> <properties> <source>*</source> </properties> </destination> </service>
5.3.
測試程式
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" horizontalCenter="true">
<mx:Script>
<![CDATA[
import mx.events.CloseEvent;
import flash.net.registerClassAlias;
import mx.rpc.AsyncToken;
import mx.controls.Alert;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.rpc.remoting.RemoteObject;
//======================================================================
private function onFault(e:FaultEvent):void{
Alert.show(e.fault.faultString, "Error");
}
//======================================================================
private function onBtnInvoke_hello_click():void{
var remObj:RemoteObject = new RemoteObject("fluorine");
remObj.source = "ServiceClsLib.Class1";
remObj.addEventListener("fault", onFault);
remObj.hello.addEventListener("result", onHello_result);
remObj.hello("Ben Chang");
}
private function onHello_result(e:ResultEvent):void{
var result:String = e.result as String;
Alert.show(result);
}
]]>
</mx:Script>
<mx:Button label="Invoke ServiceClsLib.Class1 -> hello()" click="onBtnInvoke_hello_click()"/>
</mx:Application>
測試結果:
2 意見:
邦邦你好..想請教個問題...
我們在開發一個多媒體網站
廠商是利用FluorineFx 來讓 .net 和 sql 和 flash 來開發
我們的OS 是 WIN2008 64bits
但只要web.config加入
這一段 , Server 就會出現500 錯誤
我們也試過了找出權限這部份到底哪出了問題
但始終未能有結果
不知您是否有預過類似狀況 或可以提示我們可能是哪部份有錯誤讓我們朝這方面debug
因為離結案日子越來越近 故來留言盼能有個方向解決
如您方便 我將把所有更細部的問題mail 給您
盼您能給予我們指導 謝謝
謝謝您
500 錯誤,好像是 伺服器內部錯誤,是一個很抽象的錯誤代碼,也就是等於根本不知道錯誤在哪裡,對嗎?
可能要想辦法將每個步驟切開來測試
1.
在 web.config 中,加入 httpModule 的部分,看看能否透過 FluorineFx 提供的 console 來測測基本功能是否有運作
2.
因為不確定你的安裝方式,如果你有使用比較進階的功能,可能也要確認安裝的版本:
http://www.fluorinefx.com/download.html
3.
如果步驟一的基本測試,可以透過 console 看到 .net 元件提供的服務的話,最後才來測試與 flex 整合
張貼意見