Flash Remoting For .Net 的跨域连接问题解决~
2006-11-12 19:49
471 查看
关于Flash Remoting 跨域问题,今天折腾了半天,终于有了进展。
假设Remoting Service在DomainA.com上,而一个swf发布在DomainB.com上,现在DomainB.com上的swf要连接DomainA的Remoting Service,现在就是跨域的Remoting连接了。
Flash Remoting与.Net的Remoting不同,.Net可以使用TCP或HTTP协议的传输信道,而Flash Remoting只能使用HTTP协议的传输信道,在Flash Player 5或更早版本的播放器中,跨域或子域访问不受限制,在Flash Player 7播放器中,播放器执行精确域匹配而不是超域匹配规则,即在未经允许的情形下,跨域访问是禁止的。
在Luar站上说,“SWF文件在domainA.com,Flash Remoting Gateway在domainB.com”,domainA中的swf连接domainB的Remoting Gateway,“測試過,這個當然是不可以的”。
看到这句时,心里着实凉了大半截~问了几个群,半下午,没有解决,后来实在没办法了问Peter,Peter说“跨域需要另外一个域的服务器添加配置文件”,再查帮助~哈哈~,果然可以通过域策略文件解决。
Flash Remoting要实现跨域连接,需要创建一个“crossdomain.xml”的域策略文件,名称必须为“crossdomain.xml”,然后放置在DomainA(即Remoting Service服务器)的站点根目录下。
文件内容是一个允许连接的Client端域名或IP列表,应该如:
<?xml version="1.0"?>
<cross-domain-policy>
<allow-access-from domain="192.168.39.209" />
<allow-access-from domain="*.DomainB.com" />
</cross-domain-policy>
放置后,crossdomain.xml文件应该可以这样访问:http://domainA.com/crossdomain.xml
好了,这样做就可以跨域连接Remoting Service了。
下边是具体测试代码:
1.Client端
Client端的Swf发布在192.168.39.209。
Swf 文件:
场景中放置了一个txt的动态文本框,然后在第一帧加入如下代码(AS2.0写法):
import mx.remoting.Service;
import mx.rpc.RelayResponder;
import mx.remoting.PendingCall;
import mx.rpc.ResultEvent;
import mx.rpc.FaultEvent;
import mx.services.Log;
var gatewayPath = "http://192.168.39.109/MyRemoting/gateway.aspx";
var myResponder = new RelayResponder(this, "sayGreeting_Result", "sayGreeting_Fault");
//var service:Service = new Service(gatewayPath, new Log(), "MyRemoting", null, myResponder);
var service:Service = new Service(gatewayPath, null, "MyRemoting", null, myResponder);
var mypc:PendingCall = service.test("Yao.NET");
2.Server端
Remoting Service发布在192.168.39.109,IIS中创建MyRemoting虚拟目录,此目录下有gateway.aspx,web.config,test.aspx文件及Bin目录,其中Gateway.aspx,web.config文件直接从flashremoting的samples下复制过来即可。
test.aspx文件:
<%@ Page language="c#" debug="true" %>
<%@ Register TagPrefix="Macromedia" Namespace="FlashGateway" Assembly="flashgateway" %>
<Macromedia:Flash ID="Flash" Runat="Server" />
<%
String message = "你好呀:";
if (Flash.Params.Count > 0)
Flash.Result = message;
%>
web.config中配置:
<system.web>
<httpModules>
<add name="GatewayController" type="FlashGateway.Controller.GatewayController,flashgateway" />
</httpModules>
</system.web>
Bin目录:
中有flashgateway.dll,frconfig.txt,wsdl.exe(此实例中非必须)文件,前两个文件也是直接从flashremoting的samples下复制过来即可。
---------------------------------------
以上代码,swf在Flash8中编写,test.aspx在vs.net 2003中编写,均测试通过。
最后在此感谢Peter~
假设Remoting Service在DomainA.com上,而一个swf发布在DomainB.com上,现在DomainB.com上的swf要连接DomainA的Remoting Service,现在就是跨域的Remoting连接了。
Flash Remoting与.Net的Remoting不同,.Net可以使用TCP或HTTP协议的传输信道,而Flash Remoting只能使用HTTP协议的传输信道,在Flash Player 5或更早版本的播放器中,跨域或子域访问不受限制,在Flash Player 7播放器中,播放器执行精确域匹配而不是超域匹配规则,即在未经允许的情形下,跨域访问是禁止的。
在Luar站上说,“SWF文件在domainA.com,Flash Remoting Gateway在domainB.com”,domainA中的swf连接domainB的Remoting Gateway,“測試過,這個當然是不可以的”。
看到这句时,心里着实凉了大半截~问了几个群,半下午,没有解决,后来实在没办法了问Peter,Peter说“跨域需要另外一个域的服务器添加配置文件”,再查帮助~哈哈~,果然可以通过域策略文件解决。
Flash Remoting要实现跨域连接,需要创建一个“crossdomain.xml”的域策略文件,名称必须为“crossdomain.xml”,然后放置在DomainA(即Remoting Service服务器)的站点根目录下。
文件内容是一个允许连接的Client端域名或IP列表,应该如:
<?xml version="1.0"?>
<cross-domain-policy>
<allow-access-from domain="192.168.39.209" />
<allow-access-from domain="*.DomainB.com" />
</cross-domain-policy>
放置后,crossdomain.xml文件应该可以这样访问:http://domainA.com/crossdomain.xml
好了,这样做就可以跨域连接Remoting Service了。
下边是具体测试代码:
1.Client端
Client端的Swf发布在192.168.39.209。
Swf 文件:
场景中放置了一个txt的动态文本框,然后在第一帧加入如下代码(AS2.0写法):
import mx.remoting.Service;
import mx.rpc.RelayResponder;
import mx.remoting.PendingCall;
import mx.rpc.ResultEvent;
import mx.rpc.FaultEvent;
import mx.services.Log;
var gatewayPath = "http://192.168.39.109/MyRemoting/gateway.aspx";
var myResponder = new RelayResponder(this, "sayGreeting_Result", "sayGreeting_Fault");
//var service:Service = new Service(gatewayPath, new Log(), "MyRemoting", null, myResponder);
var service:Service = new Service(gatewayPath, null, "MyRemoting", null, myResponder);
var mypc:PendingCall = service.test("Yao.NET");
2.Server端
Remoting Service发布在192.168.39.109,IIS中创建MyRemoting虚拟目录,此目录下有gateway.aspx,web.config,test.aspx文件及Bin目录,其中Gateway.aspx,web.config文件直接从flashremoting的samples下复制过来即可。
test.aspx文件:
<%@ Page language="c#" debug="true" %>
<%@ Register TagPrefix="Macromedia" Namespace="FlashGateway" Assembly="flashgateway" %>
<Macromedia:Flash ID="Flash" Runat="Server" />
<%
String message = "你好呀:";
if (Flash.Params.Count > 0)
Flash.Result = message;
%>
web.config中配置:
<system.web>
<httpModules>
<add name="GatewayController" type="FlashGateway.Controller.GatewayController,flashgateway" />
</httpModules>
</system.web>
Bin目录:
中有flashgateway.dll,frconfig.txt,wsdl.exe(此实例中非必须)文件,前两个文件也是直接从flashremoting的samples下复制过来即可。
---------------------------------------
以上代码,swf在Flash8中编写,test.aspx在vs.net 2003中编写,均测试通过。
最后在此感谢Peter~
相关文章推荐
- Flash Remoting For .Net 的跨域连接问题解决~
- Flash Remoting For .Net 的跨域连接问题解决~
- Flash Remoting For .Net 的跨域连接问题解决~
- Flash Remoting For .Net 的跨域连接问题解决~
- 安装Flash Remoting for .Net碰到的问题
- 解决ASP.NET AJAX在frame及iframe中跨域访问的问题
- (ASP.NET)C#连接Oracle数据库示例(中文乱码问题解决)
- asp.net中连接access数据库时,不能使用ISNull()T-SQL的问题解决
- 解决asp.net 连接access中的相对路径问题
- [FD] Waiting for Flash Player to connect to debugger问题与解决
- 关于flash跨域问题的解决办法
- 解决iframe跨域读写Cookies的问题,(ASP、ASP.NET、PHP、JSP)解决方案
- net use * /del /y---解决访问共享时提示多重连接的问题
- ubuntu 系统解决mysql连接问题(ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password:
- 解决跨域读写Cookies的问题,(ASP、PHP、ASP.NET、JSP)解决方案
- ubuntu 系统解决mysql连接问题(ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password:
- 解决 Navicat for Mysql连接mysql出现10038问题
- .net IIS MVC Rest api 跨域 PUT DELETE 404 无法使用问题解决方案
- 解决“在连接linux远程服务器上的mysql数据库时,报“Access denied for user 'root'@'ip地址'”问题”
- mysql 5.7.20, for Linux (x86_64) 配置远程连接 10061问题解决方案