关于FluorineFX
FluorineFX是一个开源库,提供了一种在.NET framework下对Flex/Flash的远程过程调用,Flex数据服务和实时数据的使用技术。
能被.NET frameworks支持的FluorineFx有:
特性
FluorineFx的配置
使用“FluorineFx Asp.net Web site ”向导生成的项目结构如下:
除了编写.net 服务器端代码,Flex 客户端代码。还有非常重要的就是正确的设置配置文件。配置文件将指导如何将客户端的请求重定向到正确的服务器对象(代码中体现不出来)。
打开项目根目录下的web.config 。系统向导默认的配置与fluorinefx 相关的部分( 其他的省略了) 如下:
<?xml version="1.0" encoding="utf-8" ?>
<configuration
> fluorinefx
<configSections
>
<sectionGroup
name=
"fluorinefx"
>
<section
name=
"settings"
type=
"FluorineFx.Configuration.XmlConfigurator, FluorineFx"
requirePermission=
"false"
/>
</sectionGroup
>
</configSections
>
<fluorinefx
>
<settings
>
<!-- Reflection optimizer provider="codedom|il" debug="true|false" -->
<optimizer
provider=
"codedom"
debug=
"true"
/>
<wsdlGenerateProxyClasses
>true</wsdlGenerateProxyClasses
>
<wsdlProxyNamespace
>FluorineFx.Proxy</wsdlProxyNamespace
>
<!-- Time Zone Compensation ="none|auto" -->
<timezoneCompensation
>none</timezoneCompensation
>
<!-- Any value-type that is not explicitly initialized with a value will contain the default value for that object type -->
<acceptNullValueTypes
>false</acceptNullValueTypes
>
<!-- value="browse|access" -->
<remotingServiceAttribute
>access</remotingServiceAttribute
>
<classMappings
>
<classMapping
>
<type
>SampleClassNet</type
>
<customClass
>SampleClassAS</customClass
>
</classMapping
>
</classMappings
>
<services
>
<service
>
<name
>ServiceName</name
>
<service-location
>.NET Full type name</service-location
>
<methods
>
<remote-method
>
<name
>MethodName</name
>
<method
>.NET Method name</method
>
</remote-method
>
</methods
>
</service
>
</services
>
<!-- 如果services-config.xml 没有使用,才需要设置security 部分-->
<security
>
<login-command
class=
"FluorineFx.Messaging.Security.GenericLoginCommand"
server=
"asp.net"
/>
</security
>
<cache
>
<cachedService
timeout=
"30"
slidingExpiration=
"false"
type=
".NET Full type name"
/>
</cache
>
<importNamespaces
>
<add
namespace=
"Namespace name to import"
assembly=""/>
</importNamespaces
>
<nullable
>
<type
name=
"System.Int32"
value=
"MinValue"
/>
<type
name=
"System.Double"
value=
"MinValue"
/>
<type
name=
"System.DateTime"
value=
"MinValue"
/>
<type
name=
"System.Guid"
value=
"Empty"
/>
</nullable
>
<!-- preferredAlgorithm="deflate|gzip" compressionLevel="high|normal|low" handleRequest="all|amf|none" -->
<httpCompress
preferredAlgorithm=
"gzip"
compressionLevel=
"high"
handleRequest=
"all"
>
<!-- compress responses larger then threshold bytes-->
<threshold
>10240</threshold
>
<excludedMimeTypes
>
<add
type=
"image/jpeg"
/>
<add
type=
"image/png"
/>
<add
type=
"image/gif"
/>
<add
type=
"application/zip"
/>
<add
type=
"application/x-zip-compressed"
/>
<add
type=
"application/x-gzip-compressed"
/>
<add
type=
"application/x-compressed"
/>
<add
type=
"application/octet-stream"
/>
<add
type=
"application/pdf"
/>
</excludedMimeTypes
>
<excludedPaths
>
<!--Fluorine service browser scripts and resources -->
<add
path=
"FluorineWebResource.axd"
/>
<add
path=
"FluorineCodeGenerator.aspx"
/>
<!--standard .NET validating scripts and postback script -->
<add
path=
"WebResource.axd"
/>
<!--MS AJAX and has it's own compression module that will take care of the AJAX scripts -->
<add
path=
"ScriptResource.axd"
/>
</excludedPaths
>
</httpCompress
>
<application-handler
>FluorineFx.Messaging.Adapter.ApplicationAdapter</application-handler
>
<sharedObjectService
type=
"FluorineFx.Messaging.Rtmp.SO.SharedObjectService"
>
<persistence
type=
"FluorineFx.Messaging.Rtmp.Persistence.FileStore"
/>
</sharedObjectService
>
<fluorineContextFactory
type=
"FluorineFx.Context.FluorineRtmpContextFactory"
/>
<rtmpServer
>
<threadpool
minWorkerThreads=
"0"
maxWorkerThreads=
"25"
idleTimeout=
"60000"
/>
</rtmpServer
>
</settings
>
</fluorinefx
>
...
<system.web
>
<httpModules >
<add name= "FluorineGateway" type= "FluorineFx.FluorineGateway, FluorineFx" />
</httpModules >
</system.web
>
...
</configuration >
说明: 其中,<fluorinefx /> 部分不是必须有的 ;<httpModules /> 中的"FluorineGateway" http module entry 必须有;如果没有使用services-config.xml 配置文件,才需要设置<security /> 部分。
除了根目录下的web.config 文件(asp.net 网站的标准配置文件外),WEB-INF/flex 目录下还有四个配置文件(.xml )。
由于FluorineFx 是Flex Data Service 的.net 替代品(如果你用Java 写服务器端程序,则可以直接用Flex Data Service ),FluorineFx 提供了和Flex Data Service 相同的功能— 即在services-config.xml 配置文件的<services> 部分配置Remoting Service, Message Service ,Data Management Service 。
此外,除了把所有配置都放在services-config.xml 一个文件中,还可以把Service 配置信息分散到多个配置文件里,然后包含进来以达到简化的效果。如下:
<services>
<!-- Remoting Service -->
<service-include file-path="remoting-config.xml"/>
<!-- Message Service -->
<service-include file-path="messaging-config.xml"/>
<!-- Data Management Service -->
<service-include file-path="data-management-config.xml"/>
</services>
下表是这四个配置文件的作用:
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. <!--[if !vml]--> <!--[endif]-->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 中的全局设置部分:
FluorineFx 使用Flex messaging system 中的message channel 传输消息。一个channel 可以让多个Service 通信。FluorineFx 目前不支持 AMF polling channels 。在services-config.xml 配置文件中可以设置AMF Channel 或者RTMP Channel 。如下:
<channels> <channel-definition id="my-amf" class="mx.messaging.channels.AMFChannel"> <endpoint uri="http://{server.name}:{server.port}/{context.root}/Gateway.aspx " class="flex.messaging.endpoints.AMFEndpoint "/> </channel-definition> <channel-definition id="my-rtmp" class="mx.messaging.channels.RTMPChannel"> <endpoint uri="rtmp://{server.name}:1951 " class="flex.messaging.endpoints.RTMPEndpoint "/> </channel-definition> </channels> |
这里用<channel-definition> 定义的channel ,每个都有唯一的id 。<endpoint> 的uri 设置的是一个接受用户请求的网关(Gateway.aspx )程序。打开这个网关程序,你可以发现程序中没有任何代码。
Flex 调用远程对象的流程大概如下:
<!--[if !supportLists]-->l <!--[endif]-->Flex 发出调用远程对象的请求,这个请求会被Flash Player 编码成AMF ;
<!--[if !supportLists]-->l <!--[endif]-->Flex 代码中定义了 Service 组件,通过该组件的id ,找到对应配置文件中定义的destination 。
<!--[if !supportLists]-->l <!--[endif]-->destination 通过它的channel 的 id 找到对应的channel 定义。
<!--[if !supportLists]-->l <!--[endif]-->根据channel 的定义,将请求发送给指定的gateway ;
<!--[if !supportLists]-->l <!--[endif]-->gateway 将请求发送给gateway 的后台类,将消息转换成.net 格式,调用服务器上正确的类;
接下来,针对Remoting Service, Message Service ,Data Management Service 的配置分别进行详细说明。
一、配置 RPC(remoting-config.xml)
定义Remoting Service destination 就是定义需要访问的remote object 。Remoting service destination 就是一个对象,Flex 使用<mx:RemoteObject> 或 ActionScript 代码连接这个远程对象。
例如:
<service id= "remoting-service" class= "flex.messaging.services.RemotingService" messageTypes= "flex.messaging.messages.RemotingMessage" >
<!-- Adapter 定义不是必须的, gateway 会自动的创建它-->
<adapters>
<adapter id="dotnet"
class="FluorineFx.Remoting.RemotingAdapter"
default="true"
/>
</adapters>
<default-channels>
<channel ref="my-amf"
/>
</default-channels>
<!— 下面定义一个Destination ,也就是一个远程对象 -->
<destination id = "EchoServiceRO" >
<!-- 由于上面定义了一个默认的channel ,则不需要再定义channel
<channels>
<channel ref="my-amf"/>
</channels>
-->
<properties>
<source> ServiceLibrary.EchoService </source>
<!-- <scope>application</scope> -->
</properties>
<security>
<security-constraint ref= "privileged-users" />
</security>
</destination>
...
<security>
<security-constraint id="privileged-users"
>
<auth-method>Custom</auth-method>
<roles>
<role>privilegedusers</role>
<role>admins</role>
</roles>
</security-constraint>
</security>
...
定义了远程对象,可以使用security constraint 来限制用户访问访问这个destination ( 只支持custom authentication) 。
Security constraints 可以在destination 中定义,也可以在destination 外面 定义,然后在destination 中通过Security constraints 的 id 引用。
Adapters 是服务器上的一个组件,利用Adapter ,客户端才能访问远程服务器上的 service object 。 Adapter 定义不是必需的, gateway 将自动配置它。默认的Remoting Adapter 是flex.messaging.services.RemotingService 。
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"?> <factories> <factory id= "dotnet" class= "FluorineFx.Messaging.DotNetFactory" /> </factories> <services-config> <services> <service id= "remoting-service" class= "flex.messaging.services.RemotingService" messageTypes= "flex.messaging.messages.RemotingMessage" > <!-- 所有的远程调用remote calls 都被路由到这个destination--> <destination id = "fluorine" > <channels> <channel ref= "my-amf" /> </channels> <properties> <source> * </source> </properties> </destination> <!-- 只有在Service Browsing 打开的情况下,下面的destination 才创建 --> <!-- This destination is created only when Service Browsing is enabled--> <destination id = "FluorineFx.ServiceBrowser.FluorineServiceBrowser" > <channels> <channel ref= "my-amf" /> </channels> <properties> <source> FluorineFx.ServiceBrowser.FluorineServiceBrowser </source> </properties> </destination> <!-- This destination is created only when Service Browsing is enabled--> <destination id = "FluorineFx.ServiceBrowser.ManagementService" > <channels> <channel ref= "my-amf" /> </channels> <properties> <source> FluorineFx.ServiceBrowser.ManagementService </source> </properties> </destination> <!-- This destination is created only when Service Browsing is enabled--> <destination id = "FluorineFx.ServiceBrowser.CodeGeneratorService" > <channels> <channel ref= "my-amf" /> </channels> <properties> <source> FluorineFx.ServiceBrowser.CodeGeneratorService </source> </properties> </destination> </service>
</services>
<!-- This is the LoginCommand specified in the web-config file if applicable--> <security> <login-command class= "..." server= "asp.net" /> </security>
<channels> <channel-definition id= "my-amf" class= "mx.messaging.channels.AMFChannel" > <endpoint uri= "http://{server.name}:{server.port}/{context.root}/Gateway.aspx" class= "flex.messaging.endpoints.AMFEndpoint" /> </channel-definition> </channels> </services-config> |
Message Service destination 是就是消息传输的终端(endpoint )。在这台终端机上封装有服务器端代码,处理传输过来的消息 。使用 Producer 和Consumer 组件或ActionScript API 可以连接到message service destination 。
例如:
<service id="message-service"
class="flex.messaging.services.MessageService"
messageTypes="
flex.messaging.messages.AsyncMessage"
>
<adapters>
<adapter id="chat"
class="ServiceLibrary.ChatAdapter"
default="true"
/>
</adapters>
<destination id = "chat" >
<channels>
<channel ref="my-rtmp"/>
</channels>
<properties>
<network>
<session-timeout>20</session-timeout>
</network>
<server>
<allow-subtopics>true</allow-subtopics>
</server>
<security>
<security-constraint ref="privileged-users"
/>
</security>
<properties>
</destination>
</service>
...
<security>
<security-constraint id="privileged-users"
>
<auth-method>Custom</auth-method>
<roles>
<role>privilegedusers</role>
<role>admins</role>
</roles>
</security-constraint>
</security>
...
<channels>
<channel-definition id="my-rtmp"
class="mx.messaging.channels.RTMPChannel"
>
<endpoint uri= "rtmp://{server.name}:1951" class= "flex.messaging.endpoints.RTMPEndpoint" />
</channel-definition>
</channels>
...
当前版本的FluorineFx 只支持通过Realtime Message Protocol (RTMP) channel 传输消息。
在FluorineFx 中,默认的 Message Service adapter 就是FluorineFx.Messaging.Services.Messaging.MessagingAdapter 类。所以配置文件如下设置:
<adapter id="dotnet"
class="FluorineFx.Messaging.Services.Messaging.MessagingAdapter"
default="true"
/>
如果编写MessagingAdapter 类的子类,你就可以自己定义Adapter 。
Property element |
Description |
session-timeout |
超过这个时间(单位:分钟),a subscriber is unsubscribed 。 ( 如果没有或者值为 0 ,则表明不会自动unsubscribe) |
Property element |
Description |
allow-subtopics |
Destination 是否支持subtopics (true/false) |
subtopic-separator |
不支持。所以总是"." ( 点) |
Data Management Service destination 是一个终端。这个终端可以接收数据,或者发送数据到客户机。它提供了将数据分布到多个Data Management Service destination 和 在这些destination 之间进行同步(synchronization )的能力。 在Flex 中使用DataService 组件或ActionScript API 可以连接到Data Management Service destination 。
例子:
<service id="data-service"
class="flex.data.DataService"
messageTypes="flex.data.messages.DataMessage"
>
<adapters>
<adapter id="dotnet-dao"
class="FluorineFx.DotNetAdapter"
default="true"
/>
</adapters>
<default-channels>
<channel ref="my-rtmp"
/>
</default-channels>
<destination id = "crm.company" >
<adapter ref="dotnet-dao"/>
<properties>
<source>samples.crm.CompanyAssembler
<source/>
<scope>application<scope/>
<metadata>
<identity property="companyId"/>
</metadata>
<network>
<session-timeout>20</session-timeout>
<paging enabled="true" pageSize="10"/>
</network>
</properties>
</destination>
</service>
...
<channels>
<channel-definition id="my-rtmp"
class="mx.messaging.channels.RTMPChannel"
>
<endpoint uri= "rtmp://{server.name}:1951" class= "flex.messaging.endpoints.RTMPEndpoint" />
</channel-definition>
</channels>
...
当前的FluorineFx 只支持使用Realtime Message Protocol (RTMP) channel 传输Data Management Services 。
FluorineFx 中的 Data adapter 是由 FluorineFx.DotNetAdapter 类实现的:
<adapter id="dotnet"
class="FluorineFx.DotNetAdapter"
default="true"
/>
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 |
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. |
Property element |
描述 |
identity |
Specifies data properties that provide object identity. The property attribute identifies the property name. |
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) |