职业IT人-IT人生活圈

 找回密码
 成为会员
搜索
查看: 910|回复: 1

[转帖]Flex与.NET互操作(七):

[复制链接]
蓝色梦幻 发表于 2009-3-5 10:11 | 显示全部楼层 |阅读模式
了解FluorineFx的环境配置(远程对象、网关、通道、目的地)
Flex中的远程对象访问,也就是服务端提供一个远程服务对象(RemotingService Object),在Flex客户端通过相应的访问技术去调用远程对象的过程。

     在本系列文章的前面几篇文章中所介绍的访问Webservice的方法,也就是一种远程对象方法,只不过他是基于WEB服务(WebServie)的远程访问,不是基于远程对象(Remoting Object)的的远程访问。要想直接实现基于对象的远程访问是比较麻烦的,然后FluorineFx则专门为我们提供了该功能,通过FluorineFx的核心库来开发远程对象(Remoting Object)服务,具体是怎么实现的呢?FluorineFx要求为远程对象提供[RemotingService]标记来提供远程对象服务,看看下面的RemotingServiceAttribute的详细定义:

1 [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
2 public sealed class RemotingServiceAttribute : Attribute
3 {
4     public RemotingServiceAttribute();
5     public RemotingServiceAttribute(string serviceName);
6 }

     从上一篇文章中的示例代码可以看出,使用.NET(c#)定义了一个Sample的远程对象服务类,并为其指定了[RemotingService],详细如下:
1     [RemotingService(\"Fluorine sample service\")]
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的远程对象示例,下面我们在来看看这个示例:

1     <mx:RemoteObject id=\"service\" destination=\"fluorine\"
2         source=\"FlexDotNet.ServiceLibrary.Sample\">
3             <mx:method name=\"Echo\" result=\"onResult(event)\">
4             </mx:method>
5     </mx:RemoteObject>


1     <mx:Script>
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的非可视化组件<mx:RemoteObject>进行远程对象连接。其中的source属性指定远程对象,格式为全限定名(命名空间+类名)。destination属性是非常重要的,这决定了Flex客户端是否可以正确的访问到远对象,相关配置如下:

1     <destination id=\"fluorine\">
2         <properties>
3             <source>*</source>
4         </properties>        
5     </destination>


     在<mx:RemoteObject>组件内部使用<mx:Mothod>组件配置远程对象中的方法,详细见本文前面部分。要真实实现远程对象访问的核心是对象的适配器和连接通道:

1 <?xml version=\"1.0\" encoding=\"UTF-8\"?>
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为我们提供的默认连接通道:

1     <channels>
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                 <!-- <legacy-collection>true</legacy-collection> -->
6             </properties>
7         </channel-definition>
8     </channels>
joe 发表于 2009-3-28 11:02 | 显示全部楼层
看看看。
您需要登录后才可以回帖 登录 | 成为会员

本版积分规则

QQ|手机版|小黑屋|网站帮助|职业IT人-IT人生活圈 ( 粤ICP备12053935号-1 )|网站地图
本站文章版权归原发布者及原出处所有。内容为作者个人观点,并不代表本站赞同其观点和对其真实性负责,本站只提供参考并不构成任何投资及应用建议。本站是信息平台,网站上部分文章为转载,并不用于任何商业目的,我们已经尽可能的对作者和来源进行了通告,但是能力有限或疏忽造成漏登,请及时联系我们,我们将根据著作权人的要求立即更正或者删除有关内容。

GMT+8, 2024-5-5 21:17 , Processed in 0.133943 second(s), 20 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表