Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1017179
  • 博文数量: 243
  • 博客积分: 3053
  • 博客等级: 中校
  • 技术积分: 2975
  • 用 户 组: 普通用户
  • 注册时间: 2009-05-02 21:11
文章分类

全部博文(243)

文章存档

2013年(2)

2012年(20)

2011年(5)

2010年(114)

2009年(102)

我的朋友

分类:

2010-07-13 17:21:46

先介绍一下我的测试项目,我用flash和silverlight一同来调用一个webservice,一个flash客户端,一个silverlight客户端,一个web项目来host flash和silverlight,再加上一个webservice端。
flash发布到web项目的swf文件夹下。  web项目中的clienttestpage.html中的sl和flash来调用webservice。

 具体如何调用webservice我这里就略去了。
我的webservice里有一个方法
[WebMethod]public string SayHello(string name) {    return "Hello " + name;}

webservice

Html Host页面
 
--------------------------------------------------------------------------------

这里先用silverlight来调用,在输入用户名都点击invoke按钮看看发声了什么。
在firefox中打开firebug的网络监视器
 
 这里发现他先去webservice所在的域的根目录下请求一个 clientaccesspolicy.xml 的文件,在没有到后又去请求一个crossdomain.xml的文件,同样也是没有找到,返回404。
 
好,这里我在webservice域根下放入一个clientaccesspolicy.xml
clientaccesspolicy.xml
代码
                                                   
因为webservice有requestheaders的请求,所以要加上红色部分。
再次调用看看是什么情况
请求到了clientaccesspolicy.xml 后就去真正请求webservice文件了。  并且得到了返回值。
 
接下来,去掉clientaccesspolicy.xml,加入crossdomain.xml
crossdomain.xml
   
再次调用
在没有找到clientaccesspolicy.xml的情况下,去请求crossdomain.xml文件,得到响应后就正式请求webservice文件,并且也得到了返回值。
 
--------------------------------------------------------------------------------

接下来看flash  这里用as2.0做的。 
他一开始直接就请求了crossdomain.xml,并没有去请求clientaccesspolicy.xml。
再输入用户名后,直接向webservice post数据,得到返回值。
 
好接下来看看as3的flash又会如何。

机制有些改变,一开始没去请求xml。
 
输入用户名,调用
 

再看看没有找到xml的情况

 
--------------------------------------------------------------------------------

好了在看看网上我搜索到的一些说法。
 
“出于安全考虑,FlashPlayer默认的安全设置是不允许进行跨域操作的。即便是同一个网站,如果用不同的方式访问,也会被FlashPlayer认为是跨域操作。
为解决Flash/Flex系统中的跨域问题,提出了crossdomain.xml跨域策略文件。有了它,就可以解决跨域问题。”
 
“SilverLight要实现跨域访问,必须在服务端被访问域的直接域名下,配置 clientaccesspolicy.xml( 或 crossdomain.xml)文件,即可以访问 。 ”
--------------------------------------------------------------------------------
 
 
提出问题
 关于crossdomain.xml 和 clientaccesspolicy.xml 的区别。
1、这两个文件真的是可以任选其一吗?
2、这两个文件分别需要被放在服务端还是客户端?
3、不管后台服务部署在IIS还是其它环境中,这两个文件都可以使用吗?
 
 
解答
1.silverlight在使用中可以任选其一,建议直接使用clientaccesspolicy.xml。flash只能使用crossdomain.xml。
2.都是必须在服务端被访问域的直接域名下  。
3.都可以使用
 
Silverlight supports two different mechanisms for services to opt-in to cross-domain access:
•    Place a clientaccesspolicy.xml file at the root of the domain where the service is hosted to configure the service to allow cross-domain-access.
•    Place a valid crossdomain.xml file at the root of the domain where the service is hosted. Silverlight supports a subset of the crossdomain.xml schema. This file format is supported as well by ADOBE FLASH (originally by them).
clientaccesspolicy.xml is for silverlight
view plaincopy to clipboardprint?
   
   
     
       
         
           
     
   
         
           
     
   
   
   
 
   
 


 
   
     
       
     

     
       
     

   

 

crossdomain.xml is for flash and also silverlight
view plaincopy to clipboardprint?
 
SYSTEM ""> 
 
   
 

SYSTEM "">

 
 
阅读(4229) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~