Silverlight Crossdomain Access WebService And Debug

主要是在你的Web Service目录下,放个clientaccesspolicy.xml
注意是根目录。我只有放在C:\netpub\wwwroot才行,虚拟目录下不行。

在项目中使用SilverLight调用WebService,经常出现在Debug状态下无法访问WebService的情况。

假设WebService部署在http://localhost/SonicLocalizationService /LocalizationWebService.asmx。当以Debug运行SilverLight时,SilverLight网页运行在VS的内置 Web Server中,如:http://localhost:56287/SilverlightClientWeb/。此时即被理解为跨域访问,因为端口号不一样。

 SilverLight对于跨域的访问首先从网站根目录查询clientaccesspolicy.xml文件,如果这个文件不存在,则查询 crossdomain.xml。比如网站根目录在C:\netpub\wwwroot,则在其中放入clientaccesspolicy.xml文件即可,内容如下:

 

Silverlight Crossdomain Access WebService And Debug<?xml version="1.0" encoding="utf-8" ?>
Silverlight Crossdomain Access WebService And Debug
<access-policy>
Silverlight Crossdomain Access WebService And Debug    
<cross-domain-access>
Silverlight Crossdomain Access WebService And Debug        
<policy>
Silverlight Crossdomain Access WebService And Debug            
<allow-from http-request-headers="*">
Silverlight Crossdomain Access WebService And Debug                
<domain uri="*" />
Silverlight Crossdomain Access WebService And Debug            
</allow-from>
Silverlight Crossdomain Access WebService And Debug            
<grant-to>
Silverlight Crossdomain Access WebService And Debug                
<resource path="/" include-subpaths="true" />
Silverlight Crossdomain Access WebService And Debug            
</grant-to>
Silverlight Crossdomain Access WebService And Debug        
</policy>
Silverlight Crossdomain Access WebService And Debug    
</cross-domain-access>
Silverlight Crossdomain Access WebService And Debug
</access-policy>

 我试验将clientaccesspolicy.xml删除,迫使silverlight使用crossdomain.xml,结果不行,不知道咋回事。

crossdomain.xml内容如下:

Silverlight Crossdomain Access WebService And Debug<?xml version="1.0"?>
Silverlight Crossdomain Access WebService And Debug
<!-- http://localhost/crossdomain.xml -->
Silverlight Crossdomain Access WebService And Debug
<cross-domain-policy>
Silverlight Crossdomain Access WebService And Debug    
<allow-access-from domain="*" secure="true"/>
Silverlight Crossdomain Access WebService And Debug
</cross-domain-policy>

这样就解决了跨域访问的问题



相关文章:

  • 2021-10-13
  • 2022-12-23
  • 2021-07-12
  • 2021-11-24
  • 2021-08-19
  • 2021-09-10
  • 2021-11-21
  • 2021-09-05
猜你喜欢
  • 2022-12-23
  • 2021-06-03
  • 2022-12-23
  • 2022-12-23
  • 2021-06-12
相关资源
相似解决方案