Flex中的远程对象访问,也就是服务端提供一个远程服务对象(RemotingService Object),在Flex客户端通过相应的访问技术去调用远程对象的过程。
在本系列文章的前面几篇文章中所介绍的访问Webservice的方法,也就是一种远程对象方法,只不过他是基于WEB服务(WebServie)的远程访问,不是基于远程对象(Remoting Object)的的远程访问。要想直接实现基于对象的远程访问是比较麻烦的,然后FluorineFx则专门为我们提供了该功能,通过 FluorineFx的核心库来开发远程对象(Remoting Object)服务,具体是怎么实现的呢?
FluorineFx要求为远程对象提供[RemotingService]标记来提供远程对象服务,看看下面的RemotingServiceAttribute的详细定义:
2 public sealed class RemotingServiceAttribute : Attribute
3 {
4 public RemotingServiceAttribute();
5 public RemotingServiceAttribute(string serviceName);
6 }
从上一篇文章中的示例代码可以看出,使用.NET(c#)定义了一个Sample的远程对象服务类,并为其指定了[RemotingService],详细如下:
2 public class Sample
3 {
4 public Sample()
5 {
6 }
7
8 public string Echo(string text)
9 {
10 return "Gateway echo: " + text;
11 }
12 }
从上一篇文章中搭建FluorineFx与.NET的开发环境过程中就已经出现过Flex客户端调用FluorineFx的远程对象示例,下面我们在来看看这个示例:
2 source="FlexDotNet.ServiceLibrary.Sample">
3 <mx:method name="Echo" result="onResult(event)">
4 mx:method>
5 mx:RemoteObject>
2 [CDATA[
3 import mx.rpc.events.ResultEvent;
4 internal function onClick():void
5 {
6 service.Echo(txtInput.text);
7 }
8
9 internal function onResult(evt:ResultEvent):void
10 {
11 txtResult.text = evt.result.toString();
12 }
13 ]]>
14 mx:Script>
如上可实现远程对象访问,通过Flex的非可视化组件
2 <properties>
3 <source>*source>
4 properties>
5 destination>
在
2 <service id="remoting-service"
3 class="flex.messaging.services.RemotingService"
4 messageTypes="flex.messaging.messages.RemotingMessage">
5 <adapters>
6 <adapter-definition id="dotnet" class="FluorineFx.Remoting.RemotingAdapter" default="true"/>
7 adapters>
8
9 <default-channels>
10 <channel ref="my-amf"/>
11 default-channels>
12
13 <destination id="fluorine">
14 <properties>
15 <source>*source>
16 properties>
17 destination>
18 service>
实际开发中我们可以进行自定义通信通道,默认情况下是使用FluorineFx为我们提供的默认连接通道:
2 <channel-definition id="my-amf" class="mx.messaging.channels.AMFChannel">
3 <endpoint uri="http://{server.name}:{server.port}/{context.root}/Gateway.aspx" class="flex.messaging.endpoints.AMFEndpoint"/>
4 <properties>
5
6 properties>
7 channel-definition>
8 channels>
以上就是Flex与.NET互操作 了解FluorineFx的环境配置(远程对象、网关、通道、目的地)的详细内容,更多请关注0133技术站其它相关文章!