您的位置:首页 > 其它

在Silverlight 2 中访问webservice 时,出现“The remote server returned an unexpected response: (404) Not Found”的解决办法

2008-08-13 17:17 696 查看
在silverlight 2 中访问webservice,看不见任何错误提示,在便宜下才发现 程序执行到系统自动生成的EndGetMethods(System.IAsyncResult result) 时候,提示"The remote server returned an unexpected response: (404) Not Found" ,怎么找都找不到这个为什么错误.后来在网络上才看到这个是sl 在不同的域上访问会出这样的错误, 然后把webservice 跟silverlighttestpage 的项目放在一起,就可以了。

那在不同的域的时候,应该怎么处理呢。查了一下网络的很多提示说添加clientaccesspolicy.xml 的文件,内容为

<?xml version="1.0" encoding="utf-8"?>

<access-policy>

<cross-domain-access>

<policy>

<allow-from http-request-headers="*">

<domain uri="*"/>

</allow-from>

<grant-to>

<resource path="/" include-subpaths="true"/>

</grant-to>

</policy>

</cross-domain-access>

</access-policy>

但是测试还是不行, 原因在于sl 访问的时候,是找到这个webservice.asmx站点的上一级 目录下的clientaccesspolicy.xml 文件,比如 webservice.asmx 是在“c:\inetpub\wwwroot\webservice”的目录下,而sl 查找clientaccesspolicy.xml 是在"c:\inetpub\wwwroot\" 这个目录查找的.所以你应该把clientaccesspolicy.xml 放在"c:\inetpub\wwwroot\" ,在vs调试中,因为直接引用解决方案的项目时,都是http;//localhost:端口号 ,这样就不知道要将clientaccesspolicy.xml 文件放置哪里,所以需要将webservice发布到本地iis下面,然后在执行!

主要放置的路径在webservice.asmx 站点的上一级站点目录下.如你是http://localhost/webservice 的目录,那你xml的文件放置的地址应该在 http://localhost/ 这个站点下.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐