Siverlight访问WCF The remote server returned an unexpected response: (404) Not Found 解决办法

    写完上一个试验项目,基本上技术上没有什么大的难点了,我马上开始写我计划了好几天的项目。

    不过,刚一开始,就遇到点小麻烦:Silverlight程序访问WCF服务时,调试错误信息如下:

用户代码未处理 System.ServiceModel.ProtocolException
  Message="The remote server returned an unexpected response: (404) Not Found."
  StackTrace:
       位于 System.ServiceModel.AsyncResult.End[TAsyncResult](IAsyncResult result)
       位于 System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.End(SendAsyncResult result)
       位于 System.ServiceModel.Channels.ServiceChannel.EndCall(String action, Object[] outs, IAsyncResult result)
       位于 System.ServiceModel.ClientBase`1.ChannelBase`1.EndInvoke(String methodName, Object[] args, IAsyncResult result)
       位于 TISCS.Bamhut.Paper.BamhutService.BamhutServiceClient.BamhutServiceClientChannel.EndUserLogin(IAsyncResult result)
       位于 TISCS.Bamhut.Paper.BamhutService.BamhutServiceClient.TISCS.Bamhut.Paper.BamhutService.IBamhutService.EndUserLogin(IAsyncResult result)
       位于 TISCS.Bamhut.Paper.BamhutService.BamhutServiceClient.OnEndUserLogin(IAsyncResult result)
       位于 System.ServiceModel.ClientBase`1.OnAsyncCallCompleted(IAsyncResult result)
  InnerException:

    郁闷!到网上找了找资料,参考了一下这两个帖子:

一:http://forums.iis.net/t/1149643.aspx  二:http://www.cnblogs.com/invinboy/archive/2008/06/29/1232037.html

    大概的意思是添加一个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>

    至于这个文件的存放位置,帖子二做了较详细的说明,但我个人认为还不够详细,其实,这个文件,是要放在IIS站点的根目录下的,不是WCF所在目录,也不是Web项目根目录,更不是Silverlight所在的目录,一定要在localhost所在的物理目录!

    问题已解决,解决方案给大家共享一下。以上内容如有错误或疏漏,敬请指正。

你可能感兴趣的:(response)