Flex3 remoting通讯
今天下午又和.net工程师研究了一下关于remoting的问题,这次的课题主要是Flex与remoting的通讯.
注 .net部分为Fluorine
感觉收获蛮多,所以决定原创一帖(转了那么多前辈们的文章,怎么也要原创一个^_^)
不过如果你想多看看有关remoting的相关知识,我还是有有推荐的
Flex以及Remoting与后台的一些文章教程收
Flex3与remoting通讯的2中配置方法
第一种配置方法:
1、在新建的Flex项目中选择ColdFusion Flash Remoting。如图:
2、Deployed to J2EE server。如图:
第二种配置方法:(推荐)
1、部署配置文件 services_config.xml
<?xml version="1.0" encoding="UTF-8"?>
<services-config>
<services>
<service id="remoting-service"
class="flex.messaging.services.RemotingService"
messageTypes="flex.messaging.messages.RemotingMessage">
<destination id="fluorine">
<channels>
<channel ref="my-amf"/>
</channels>
<properties>
<source>*</source>
</properties>
</destination>
</service>
</services>
<channels>
<channel-definition id="my-amf" class="mx.messaging.channels.AMFChannel">
<endpoint uri="http://localhost:2355/WebSite1/Gateway.aspx" class="flex.messaging.endpoints.AMFEndpoint"/>
</channel-definition>
</channels>
</services-config>
注:1、uri部分为你的aspx接口地址。2、将这个文件放入src目录下
2、Flex启动配置
部署好文件之后要将该文件设置为Flex的启动配置项
Flex客户端的测试代码
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
<mx:RemoteObject
id="service"
destination="fluorine"
source="remoting.Sample"
showBusyCursor="true" />
<mx:TextInput id="txtName"/>
<mx:Button label="Say Hello" click="service.echo(txtName.text)"/>
<mx:Label text="{service.echo.lastResult}" fontSize="18"/>
</mx:Application>
.net服务器端的测试代码
在app_code下建立了一个remoting的包,内建了一个Sample的类,内建一个echo方法
using System;
using FluorineFx.Management.Web;
using FluorineFx;
using System.Data;
using System.Data.Common;
namespace remoting
{
[RemotingService()]
public class Sample
{
public string echo(string test)
{
return test;
}
}
}