关于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相关的部分(其他的省略了)如下:
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会使用下面的默认配置:
*
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)