FluorineFX開源庫 使用教程

轉載請保留出處: DDV=敵敵畏 www.dplayer.net

關於FluorineFX

FluorineFX是一個開源庫,提供了一種在.NET framework下對Flex/Flash的遠程過程調用,Flex數據服務和實時數據的使用技術。

能被.NET frameworks支持的FluorineFx有:

  • Microsoft .NET Framework 1.1 (1.1.4322)
  • Microsoft .NET Framework 2.0 (2.0.50727)
  • Microsoft .NET Framework 3.5 (3.5.21022.8)
  • Mono 1.2.4
  • .NET frameworks 支持向下兼容,所以新版本的框架將運行的二進制集會被定位到先前版本的框架

特性

  • Flex, Flash Remoting (RPC)
  • Flex Messaging (partial)
  • Flex Data Services (partial)
  • Supports AMF0, AMF3 and RTMP protocols
  • Service Browser
  • Template based code generator (ASP.NET like syntax)
  • Easily integrate rich Internet applications with .NET backend
  • Easily integrate with Adobe Integrated Runtime (Adobe AIR™)

FluorineFx的配置

使用“FluorineFx Asp.net Web site”嚮導生成的項目結構如下:

除了編寫.net服務器端代碼,Flex客戶端代碼。還有非常重要的就是正確的設置配置文件。配置文件將指導如何將客戶端的請求重定向到正確的服務器對象(代碼中體現不出來)。

打開項目根目錄下的web.config。系統嚮導默認的配置與fluorinefx相關的部分(其他的省略了)如下:

<?xml version="1.0" encoding="utf-8" ?>
 fluorinefx
  
    
      
    
  
 
  
    
      
      
      true
      FluorineFx.Proxy
      
      none
      
      false
      
      access
      
        
          SampleClassNet
          SampleClassAS
        
      
      
        
          ServiceName
          .NET Full type name
          
            
              MethodName
              .NET Method name
            
          
        
      
      
      
        
      
      
        
      
      
        
      
      
        
        
        
        
      
      
      
        
        10240
        
           
           
           
           
           
           
           
           
           
        
        
           
           
           
           
           
           
           
        
      
      FluorineFx.Messaging.Adapter.ApplicationAdapter
      
        
      
      
      
        
      
    
  
 
  ...
  
    
      
    
  
  ...

說明:其中,部分不是必須有的 ;中的"FluorineGateway" http module entry 必須有;如果沒有使用services-config.xml配置文件,才需要設置部分。

除了根目錄下的web.config文件(asp.net網站的標準配置文件外),WEB-INF/flex目錄下還有四個配置文件(.xml)。

由於FluorineFx是Flex Data Service的.net替代品(如果你用Java寫服務器端程序,則可以直接用Flex Data Service),FluorineFx提供了和Flex Data Service相同的功能—即在services-config.xml配置文件的部分配置Remoting Service, Message Service ,Data Management Service。

此外,除了把所有配置都放在services-config.xml一個文件中,還可以把Service配置信息分散到多個配置文件裏,然後包含進來以達到簡化的效果。如下:

  
    
    
    
    
    
    
  

下表是這四個配置文件的作用:

services-config.xml

頂層的配置文件。包含有 Contains security constraint 定義, channel 定義, service 定義。

remoting-config.xml

Remoting Service destination定義,用於訪問remote objects。

messaging-config.xml

Message Service destination定義,用於publish subscribe messaging。

data-management-config.xml

Data Management Service destination定義。

看上去這些配置文件和Flex Data Service保持一致。沒錯,FluorineFx 配置文件與Flex/Flash保持了統一。

這四個XML格式的配置文件中可以使用的XML elements如下表:

XML element

描述

services

services-config是XML配置文件的根節點,而services是services-config的第一個字節點(屬於配置的頂層元素)

services/service-include

Includes files by reference that contain service definitions

services/service

Definition for a service (Remoting Service, Message Service, Data Management Service)

services/service/properties

Service-level properties

services/service/adapters

Definitions for service adapters that are referenced in destinations

services/service/adapters/adapter-definition

Service adapter definition

services/service/default-channels

References to a service's default channels (when a channel is not explicitly referenced in a destination)

services/service/default-channels/channel

References to the id of a channel definition

services/service/destination

Destination definition

services/service/destination/adapter

A reference to a service adapter

services/service/destination/properties

Destination properties

services/service/destination/channels

References to the channels that the service can use for data transport

services/service/destination/channels/channel

References to the id of a channel definition

services/service/destination/security

Complete security constraint definitions or references to security constraint definitions and login command definitions that are used for authentication and authorization

services/service/destination/security/security-constraint

References to the id value of a security constraint definition or contains a security constraint definition

services/service/destination/security/security-constraint/roles

Names of roles used for authorization

services/service/destination/security/login-command

References to the id value of a login command definition that is used for performing custom authentication.

Not supported

security

Security constraint definitions and login command definitions for authentication and authorization

security/security-constraint

Defines a security constraint

security/security-constraint/roles

Names of roles used for authorization

security/login-command

Defines a login command used for custom authentication

channels

Definitions of message channels used to transport data between the server and clients

channels/channel-definition

Defines a message channel to transport data

channels/channel-definition/endpoint

Specifies the endpoint URI and the endpoint class of the channel definition

channels/channel-definition/properties

Properties of a channel definition

在這些配置部分,有些針對於所有的全部的Service(在services-config.xml設置),有些則專用於特定的Service(在remoting-config.xml/ messaging-config.xml/ data-management-config.xml中設置)。

先看看services-config.xml中的全局設置部分:

1.配置message channel

FluorineFx 使用Flex messaging system 中的message channel傳輸消息。一個channel可以讓多個Service通信。FluorineFx目前不支持AMF polling channels 。在services-config.xml配置文件中可以設置AMF Channel 或者RTMP Channel。如下:

class="flex.messaging.endpoints.AMFEndpoint"/>

這裏用定義的channel,每個都有唯一的id。的uri設置的是一個接受用戶請求的網關(Gateway.aspx)程序。打開這個網關程序,你可以發現程序中沒有任何代碼。

Flex調用遠程對象的流程大概如下:

l Flex發出調用遠程對象的請求,這個請求會被Flash Player編碼成AMF;

l Flex代碼中定義了 Service組件,通過該組件的id,找到對應配置文件中定義的destination。

l destination通過它的channel 的 id找到對應的channel定義。

l 根據channel的定義,將請求發送給指定的gateway;

l gateway將請求發送給gateway的後臺類,將消息轉換成.net格式,調用服務器上正確的類;

接下來,針對Remoting Service, Message Service ,Data Management Service的配置分別進行詳細說明。

一、配置RPC(remoting-config.xml)

定義Remoting Service destination就是定義需要訪問的remote object。Remoting service destination就是一個對象,Flex使用或 ActionScript代碼連接這個遠程對象。

例如:

"remoting-service" class="flex.messaging.services.RemotingService" messageTypes="flex.messaging.messages.RemotingMessage">

    


    

下面定義一個Destination,也就是一個遠程對象 -->
id="EchoServiceRO">
  
  
    ServiceLibrary.EchoService
    
  
  
    
  
 
...

    
        Custom
        
            privilegedusers
            admins
         
    

... 

對上面配置的說明:

1.的安全設置

定義了遠程對象,可以使用security constraint來限制用戶訪問訪問這個destination (只支持custom authentication)。

Security constraints 可以在destination中定義,也可以在destination外面 定義,然後在destination中通過Security constraints的 id引用。

2.Destination adapter

Adapters是服務器上的一個組件,利用Adapter,客戶端才能訪問遠程服務器上的 service object。 Adapter 定義不是必需的, gateway 將自動配置它。默認的Remoting Adapter是flex.messaging.services.RemotingService。

3.Remote object 的

Property element

描述

source

Fully qualified type name of the .NET object (remoting service)

scope

可以設置爲 request, application, session。默認值爲“ request”。

如果爲“request”,則Objects是無狀態的stateless ( remoting service object is instantiated for every request);如果爲“application”,則整個application都可以訪問這個object;

如果爲“session”,則相同的session可以使用 (a single remoting service object is created per asp.net session).

4.Web service properties(還不支持)

Property element

描述

wsdl

不支持

soap

不支持

5.默認設置

如果沒有service配置文件,則gateway會使用下面的默認配置:

<?xml version="1.0" encoding="UTF-8"?>

*

FluorineFx.ServiceBrowser.FluorineServiceBrowser

FluorineFx.ServiceBrowser.ManagementService

FluorineFx.ServiceBrowser.CodeGeneratorService


二、配置 Message Service

Message Service destination 是就是消息傳輸的終端(endpoint)。在這臺終端機上封裝有服務器端代碼,處理傳輸過來的消息 。使用 Producer 和Consumer 組件或ActionScript API可以連接到message service destination。

例如:



    

 
id="chat">
    
        
    
    
        
            20
        
        
            true
        
        
            
        
    


...

    
        Custom
        
            privilegedusers
            admins
         
    

... 

    
        
    

...

對上面配置的說明:

1.Message channels

當前版本的FluorineFx 只支持通過Realtime Message Protocol (RTMP) channel傳輸消息。

2.Message Service adapter

在FluorineFx中,默認的 Message Service adapter就是FluorineFx.Messaging.Services.Messaging.MessagingAdapter 類。所以配置文件如下設置:

    

如果編寫MessagingAdapter類的子類,你就可以自己定義Adapter 。

3.Network properties

Property element

Description

session-timeout

超過這個時間(單位:分鐘),a subscriber is unsubscribed。 (如果沒有或者值爲 0 ,則表明不會自動unsubscribe)

4.Server properties

Property element

Description

allow-subtopics

Destination是否支持subtopics (true/false)

subtopic-separator

不支持。所以總是"." (點)


三、配置 Data Management Service

Data Management Service destination 是一個終端。這個終端可以接收數據,或者發送數據到客戶機。它提供了將數據分佈到多個Data Management Service destination和 在這些destination之間進行同步(synchronization)的能力。 在Flex中使用DataService 組件或ActionScript API可以連接到Data Management Service destination。

例子:



    


    

 
id="crm.company">
    
    
        samples.crm.CompanyAssembler
        application
        
            
        
        
            20
            
        
        


... 

    
        
    

...
              

對上面配置的說明:

1.Message channel的選擇:

當前的FluorineFx 只支持使用Realtime Message Protocol (RTMP) channel 傳輸Data Management Services。

2.Data adapter的設置:

FluorineFx中的 Data adapter是由 FluorineFx.DotNetAdapter 類實現的:

    

3.Destination properties

Property element

描述

source

Fully qualified type name of the Data Assembler

scope

Valid values are request, application, and session. The default value is request.

cache-items

不支持, 總設置成true

auto-sync-enabled

不支持, 總設置成true

4.Network properties

Property element

描述

session-timeout

Idle time in minutes before a subscriber is unsubscribed (Missing element or the value 0 means do not unsubscribe automatically)

paging

Optional element specifying data paging settings. The enabled attribute (true/false) indicates whether data paging is enabled for the destination, the pageSize attribute indicates the number of records in a page.

5.Metadata properties

Property element

描述

identity

Specifies data properties that provide object identity. The property attribute identifies the property name.

6.Server properties

Property element

描述

allow-subtopics

Specifies whether subtopics are allowed for a destination (true/false)

subtopic-separator

Not supported. In FluorineFx the subtopic separator is always "." (period)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章