在Silverlight 2 beta 2中,访问webservice 或者 wcf 的时候,常常会出现这样的错误:
An exception of type 'System.ServiceModel.ProtocolException' occurred in System.ServiceModel.dll but was not handled in user code
Additional information: The remote server returned an unexpected response: (404) Not Found.
   在地址栏中,直接输入asmx 或者.svc 文件,运行一切正常。
   查了下资料,发现是客户端跨域访问策略文件(clientaccesspolicy.xml)产生的问题。
   正确的文件应该是:


     但是,很多网友却很迷惑,这个文件在什么地方?或者找到了地方,修改了为什么还是不生效呢?
     原来是clientaccesspolicy.xml 文件的地址不正确,比如我们webservice目录叫做webservice1,引用地址是http://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.asmx 发布到IIS中(http://localhost/webservice1/webservice.asmx),然后再进行调试,这样一般都能解决问题。

 

相关文章:

  • 2021-09-26
  • 2021-10-15
  • 2021-12-14
  • 2021-12-09
  • 2021-12-02
  • 2021-09-12
  • 2021-09-06
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-05
  • 2021-06-06
  • 2022-12-23
相关资源
相似解决方案