FMS如何连接FlashRemoting

FMS如何连接FlashRemoting

FROM:冰山上的播客

 

在FMS开发中,我们经常要在FMS端连接数据库,进行如身份验证等的数据查询操作。方法有多种,你可以使用WebServices或NetConnection对象,也可以使用NetServices类,差别是NetServices能够返回RecordSet对象的数据,本例子就是一个使用NetServices连接FlashRemoting程序的简单例子。例子的重点在于跑通“Flash->FMS->FlashRemoting”这个数据传递的过程,所以并没有使用到RecordSet对象。例子使用Flash 8 + FMS 2.0.4 + Asp.Net 2.0 制作。

点此下载(74KB)FMS_FlashRemoting.rar 随后请修改扩展名

一、使用说明
1).在IIS中,创建虚拟目录RemotingApp,asp.net版本选择2.0,将例子中RemotingApp文件夹中的内容放进去;
2).将crossdomain.xml文件放在IIS站点根中,要能通过http://domain/crossdomain.xml访问;
3).将FMSRemotingTest文件夹copy到FMS的应用程序目录中,此目录默认在“C:/Program Files/Macromedia/Flash Media Server 2/applications/”

一、关键代码分析
1).TestDemo.aspx

<%@ Page Language=c# Debug=true %>

<%@ Register TagPrefix=Macromedia Namespace=FlashGateway Assembly=flashgateway %>
<Macromedia:Flash ID=Flash1 runat=Server />

<script language=C# runat=server>
void Page_Load(Object sender, EventArgs e)
{
Flash1.Result
= FlashRemoting服务器时间:+System.DateTime.Now.ToString(yyyy-MM-dd hh:mm:ss);
}
</script>

注意加粗的部分,FlashRemoting是个比较特殊的东西,你的页面”TestDemo.aspx“的名称”TestDemo”就是方法名称,方法的代码要写在Page_Load中,然后把返回结果绑定到一个FlashGateway对象(本例中”Flash1″)上才能传递出去。关于FlashRemoting For .Net的详细用法,请查其它资料。

2).FMS端Main.asc文件

load (netservices.asc);
//
application.onConnect = function (client, _name)
{
//…
this.acceptConnection (client);
//
NetServices.setDefaultGatewayUrl (”http://localhost/RemotingApp/gateway.aspx”);
var conn = NetServices.createGatewayConnection ();
var myService = conn.getService (RemotingApp, this);
myService.TestDemo();
application.TestDemo_Result = function (result_obj)
{
//…
}
//…
};
同样注意加粗的部分,load (netservices.asc);要放在最顶行。
RemotingApp“就是前边创建的虚拟目录了。
conn.getService (RemotingApp, this);这一句这里要非常注意,如果你的aspx页面放在更深一层的目录中,那么这一句中的RemotingApp,就要带把路径转换为类似命名空间的写法,如“RemotingApp.Folder”。
TestDemo“就是前边TestDemo.aspx页面的名称,接受数据的函数使用”Remoting方法名”+”_Result”的格式。

3).FMS_FlashRemoting.fla文件
这个没啥说的,很简单,略了。

二、注意事项
如果遇到不能成功连接和返回数据,请注意:
1).安全策略的问题,前边放置”crossdomain.xml“就是解决这个问题。
2).web.config中system.web节的是否有:

<httpModules>
<add name=”GatewayController” type=”FlashGateway.Controller.GatewayController,flashgateway” />
</httpModules>



三、本例的测试运行效果

如下图:

FMS_FlashRemoting00.gif


四、另附两个开发过程中遇到的简单问题
1.如何查看FMS的服务端trace出的信息?
1).打开FMS的管理控制台;
2).View Applications -> { FMSRemotingTest } -> LiveLog;如下图:

FMS_FlashRemoting01.gif


2.如何重启FMS应用程序?
修改了FMS服务端的程序,如Main.asc后,需要重启FMS的应用程序才能看到最新的结果,所以如果你改了代码而看不到最新效果,不要恼火,还需要这步操作。
1).打开FMS的管理控制台;
2).Manage Servers -> { FMSRemotingTest } -> 如下图:

FMS_FlashRemoting02.gif

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值