点此下载(74KB)>>
一、使用说明
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 >
<%@ 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 >
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)
{
//...
}
//...
};
//
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 >
< add name ="GatewayController" type ="FlashGateway.Controller.GatewayController,flashgateway" />
</ httpModules >
四、本例的测试运行效果
如下图:
![](https://i-blog.csdnimg.cn/blog_migrate/c3b77b649ed05a0ee01684635986d3bf.gif)
五、另附两个开发过程中遇到的简单问题
1.如何查看FMS的服务端trace出的信息?
1).打开FMS的管理控制台;
2).View Applications -> { FMSRemotingTest } -> LiveLog;如下图:
![](https://i-blog.csdnimg.cn/blog_migrate/9008d20fe2b16f95178a285a35aa16ea.gif)
2.如何重启FMS应用程序?
修改了FMS服务端的程序,如Main.asc后,需要重启FMS的应用程序才能看到最新的结果,所以如果你改了代码而看不到最新效果,不要恼火,还需要这步操作。
1).打开FMS的管理控制台;
2).Manage Servers -> { FMSRemotingTest } -> 如下图:
![](https://i-blog.csdnimg.cn/blog_migrate/25d5ebe077c3f5f26ea88b5be6fc45be.gif)