我正在使用一个使用WCF服务的Silvelright应用程序,我已经在IIS的wwwroot和应用程序文件夹中放置了一个跨域和客户端访问策略xml!
然而,当客户端与服务通信时,它抛出一个错误:
尝试向URI‘http://localhost:1528/MyService.svc’发出请求时出错。这可能是由于试图在没有适当的跨域策略的情况下以跨域的方式访问服务,或者是因为策略不适合SOAP服务。您可能需要联系服务的所有者以发布……
请帮帮我!谢谢
发布于 2010-05-17 21:26:48
clientaccesspolicy.xml需要与您的服务位于同一端口。它需要位于http://localhost:1528/clientaccesspolicy.xml
如果你在自托管WCF服务,那么你需要在你的WCF服务中托管clientaccesspolicy.xml。我找到的最简单的方法是添加一个单独的服务契约,它提供clientaccesspolicy.xml的HTTP GET。
[ServiceContract()]
public class PolicyRetriever
{
[OperationContract, WebGet(UriTemplate = "/clientaccesspolicy.xml")]
public Stream GetSilverlightPolicy()
{
string result = @"<?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>";
if (System.ServiceModel.Web.WebOperationContext.Current != null)
{
System.ServiceModel.Web.WebOperationContext.Current.OutgoingResponse.ContentType = "application/xml";
}
return new MemoryStream(Encoding.UTF8.GetBytes(result));
}
}https://stackoverflow.com/questions/2848608
复制相似问题