跨域错误 - Silverlight - WCF自托管服务

时间:2012-09-12 15:16:38

标签: c# wcf silverlight soap windows-services

我正在尝试点击我创建的使用HTTPS的自托管WCF服务。我可以使用WCFClientTest工具和Web浏览器来访问该服务但是我的silverlight应用程序无法运行。我收到以下错误:

This could be due to to attempting to access a service in a cross-domain way without a proper cross-domain policy in place, or a policy that is unsuitable for SOAP services. You may need to contact the owner of the service to publish a cross-domain policy file and to ensure it allows SOAP-related HTTP headers to be sent.

我确实有clientaccesspolicy.xml,当我通过提琴手查看时,我可以看到silverlight应用程序正常运行。 xml文件包含以下内容:

<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>

问题是,即使silverlight应用程序似乎正在请求和接收该文件,它仍然会抛出它需要允许跨域访问的错误消息..任何想法??

提前致谢。

2 个答案:

答案 0 :(得分:2)

注意应用程序尝试使用WCF服务的地址和端口。使用Fiddler来查看它的调用位置(我有很多这样的问题,因为VS的错误是相同的......它没有找到服务)。

无论如何,你有一个正在运行的clientaccesspolicy.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 path="/" include-subpaths="true"/>
      </grant-to>
    </policy>
  </cross-domain-access>
</access-policy>

答案 1 :(得分:0)

您需要一个针对https的单独域节点:

<domain uri="https://*" /> 

访问以了解有关Cros Domain的更多信息:http://msdn.microsoft.com/en-us/library/dd470115(VS.95).aspx&amp; http://blogs.msdn.com/b/carlosfigueira/archive/2008/03/07/enabling-cross-domain-calls-for-silverlight-apps-on-self-hosted-web-services.aspx

愿这个链接有帮助。

相关问题