【问题标题】:Cross Domain Error - Silverlight - WCF self hosted service跨域错误 - Silverlight - WCF 自托管服务
【发布时间】:2012-09-05 15:56:29
【问题描述】:

我正在尝试访问我创建的使用 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 应用程序似乎正在请求并接收该文件,它仍然会抛出错误消息,它需要允许跨域访问..​​ 有什么想法吗??

提前致谢。

【问题讨论】:

    标签: c# wcf silverlight soap windows-services


    【解决方案1】:

    注意您的应用程序尝试使用 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>
    

    【讨论】:

      【解决方案2】:

      您需要一个单独的域节点用于 https:

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

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

      希望此链接有所帮助。

      【讨论】:

      • 第二个链接实际上是我遵循的实现这个 :) 第一个链接说我需要把 放在我的 allow-from;但是,我现在有 uri="*" .. 这会导致问题吗??
      猜你喜欢
      • 2012-08-24
      • 1970-01-01
      • 1970-01-01
      • 2011-10-15
      • 1970-01-01
      • 2011-11-03
      • 2010-11-24
      • 2011-08-27
      • 1970-01-01
      相关资源
      最近更新 更多