积极答复者
Silverlight调用以WPF程序为宿主的WCF服务方法出错

问题
-
错误信息:
尝试向 URI“url”发出请求时出错。这可能是由于试图以跨域方式访问服务而又没有正确的跨域策略,或策略不适用于 SOAP 服务。您可能需要与该服务的所有者联系,以发布跨域策略文件并确保该文件允许发送 SOAP 相关的 HTTP 标头。出现此错误也可能是由于使用的是 Web 服务代理中的内部类型而没有使用 InternalsVisibleToAttribute 属性。有关详细信息,请参阅内部异常。
把跨域文件复制到网站目录,或者WPF程序的运行目录都没用.
WPF程序中关于WCF代码:
ServiceHost host = new ServiceHost(typeof(ServiceCore));
host.AddServiceEndpoint(typeof(IServiceCore), new BasicHttpBinding(), "url");
ServiceMetadataBehavior behavior = new ServiceMetadataBehavior() { HttpGetEnabled = true, HttpGetUrl = new Uri("url") };
host.Description.Behaviors.Add(behavior);
host.Open();Silverlight可以正常引用,但调用WCF里面的方法就出错.
WCF服务接口以及实现:
[ServiceContract]
public interface IServiceCore
{
[OperationContract]
string DoWork();
}public class ServiceCore : IServiceCore
{
public string DoWork()
{
return "Hello";
}
}我是包子!
答案
-
将clientaccesspolicy.xml或crossdomain.xml文件必须位于web server的根目录,在Silverlight 3.0版本以上,clientaccesspolicy.xml文件必须包含http-request-headers属性,试着将<allow-from>改为<allow-from http-request-headers="*">看看,你可以参考下面几篇文章.
http://www.jstawski.com/archive/2010/02/05/1236.aspx
http://www.devtoolshed.com/explanation-cross-domain-and-client-access-policy-files-silverlightPlease mark the replies as answers if they help or unmark if not. If you have any feedback about my replies, please contact msdnmg@microsoft.com Microsoft One Code Framework
- 已标记为答案 Peter pi - MSFTModerator 2012年3月28日 0:58
全部回复
-
跨域文件复制到根目录是没有用的,
http://www.cnblogs.com/jillzhang/archive/2008/07/14/1242939.html
参考这个,在浏览器中 http:\\ip地址:端口\跨域文件.xml 能读取出来才能跨域
-
将clientaccesspolicy.xml或crossdomain.xml文件必须位于web server的根目录,在Silverlight 3.0版本以上,clientaccesspolicy.xml文件必须包含http-request-headers属性,试着将<allow-from>改为<allow-from http-request-headers="*">看看,你可以参考下面几篇文章.
http://www.jstawski.com/archive/2010/02/05/1236.aspx
http://www.devtoolshed.com/explanation-cross-domain-and-client-access-policy-files-silverlightPlease mark the replies as answers if they help or unmark if not. If you have any feedback about my replies, please contact msdnmg@microsoft.com Microsoft One Code Framework
- 已标记为答案 Peter pi - MSFTModerator 2012年3月28日 0:58