The remote server returned an unexpected response: (404) Not Found

在silverlight 中调用webService的webMethod

 

在结束这个方法 public Ods.Application.ServiceReference1.User EndGetUserByID(System.IAsyncResult result) 时(GetUserByID是我定义的Web方法)出现The remote server returned an unexpected response: (404) Not Found.

 

查了一下资料,出现此问题的原因是,客户端跨域访问策略文件(clientaccesspolicy.xml)产生的问题clientaccesspolicy.xml 文件的地址不正确.

比如我们webservice目录叫做webservice1,引用地址是p://localhost/webservice1/webservice.asmx,而silverlight不是在http://localhost/webservice1这个目录下找clientaccesspolicy.xml,而是在http://localhost/下找这个文件.所以假如你的IIS默认目是"c:/inetpub/wwwroot"的话,webservice1/webservice.asmx是部署在“c:/inetpub/wwwroot/webservice1”下,那么clientaccesspolicy.xml 就应该放在“c:/inetpub/wwwroot”而不是c:/inetpub/wwwroot/webservice1 下面。但是VS2008 在调试状态下运行的时候,其URL通常是http://localhost/:端口号/webservice.asmx ,这种情况下可以直接将clientaccesspolicy.xml 文件放到你的webservice项目文件的根目录下。

 

附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>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值