如果之前有人问过这个问题(我在任何地方都找不到答案),我深表歉意,但我已经创建了一个 WCF 服务应用程序,并且正在尝试通过我的 Silverlight 4 应用程序进行访问。我已将服务引用添加到 SilverLight 应用程序,并且只是尝试调用服务上默认的现有方法之一 (GetData)。调用该方法时出现错误:
An error occurred while trying to make a request to URI "my URI" This could be due to attempting to access a service in a cross-domain way without a proper cross-domain policy in place, or a policy file that is unsuitable for SOAP Services.
我知道我需要一个 crossdomain.xml 文件,但我将 crossdomain.xml 文件放在哪里似乎并不重要,我仍然收到错误,这是文件的内容:
<?xml version="1.0" encoding="utf-8"?>
<access-policy>
<cross-domain-access>
<policy>
<allow-from http-request-headers="SOAPAction">
<domain uri="http://*"/>
<domain uri="https://*" />
</allow-from>
<grant-to>
<resource include-subpaths="true" path="/"/>
</grant-to>
</policy>
</cross-domain-access>
</access-policy>
有什么想法吗?
最佳答案
将策略文件放置在何处确实很重要 - 它需要放置在运行您的服务的 Web 服务器的“根目录”。
这在http://msdn.microsoft.com/en-us/library/cc197955(VS.95).aspx中有很好的记录。
关于这些问题,我最好的建议是运行 Fiddler 工具并跟踪流量,您应该看到 Silverlight 正在寻找 clientaccesspolicy.xml 文件(以及不同格式的 crossdomain.xml 文件),这应该可以实现更容易确定 Silverlight 在何处查找文件。
迈克。
关于c# - WCF 和 Silverlight CrossDomain.xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3156132/