游子吟

致力于.Net,致力于企业信息化工程!
Harvest = Hope + Struggle

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

    在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 文件


     但是,很多网友却很迷惑,这个文件在什么地方?或者找到了地方,修改了为什么还是不生效呢?
     原来是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),然后再进行调试,这样一般都能解决问题。

 

posted on 2008-06-29 16:32  巴山游子  阅读(1698)  评论(3编辑  收藏  举报