Silverlight WCF服务跨域问题 [英] Silverlight WCF Service Cross Domain Question

查看:158
本文介绍了Silverlight WCF服务跨域问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个silverlight应用程序(托管在intranet.mydomain.net)和一个WCF服务(webservices.mydomain.net)

I have a silverlight app (hosted at intranet.mydomain.net) and a WCF service at (webservices.mydomain.net)

站点策略文件?

推荐答案

是的,你需要一个

默认情况下,Silverlight支持在同一个域或站点上对Web服务的调用,这些调用都是在服务域(webservices.mydomain.net)的ROOT中创建的。起源。相同域意味着呼叫必须使用相同的子域,协议和端口。这是出于安全原因,并防止跨域伪造。

By default, Silverlight supports calls to Web services on the same domain or site of origin. Same domain means that calls must use the same sub domain, protocol, and port. This is for security reasons and prevents cross-domain forgery.

这是一个示例文件:

<?xml version="1.0" encoding="utf-8" ?>
<access-policy>
  <cross-domain-access>
    <policy>
      <allow-from http-request-headers="*">
        <domain uri="http://intranet.mydomain.net"/>
      </allow-from>
      <grant-to>
        <resource path="/" include-subpaths="true"/>
      </grant-to>
    </policy>
  </cross-domain-access>
</access-policy>

这将允许来自intranet.mydomain.net的请求。

This would allow requests only from intranet.mydomain.net.

编辑

已被要求:
如果我有两个WCF服务,这将如何工作? /ServiceA/a.svc和/ServiceB/b.svc,我想让ServiceA对任何人,任何地方开放,并且ServiceB只能从我的Intranet工作?

It has been asked: How would this work if I have two WCF Services? /ServiceA/a.svc and /ServiceB/b.svc and I want ServiceA to to be open to anyone, anywhere, and ServiceB to only work from my intranet?

您的政策文件将如下所示:

Your policy file would look like this:

<?xml version="1.0" encoding="utf-8" ?>
<access-policy>
  <cross-domain-access>
    <policy>
      <allow-from http-request-headers="*">
        <domain uri="http://*"/>
      </allow-from>
      <grant-to>
        <resource path="/ServiceA/" include-subpaths="true"/>
      </grant-to>
    </policy>

    <policy>
      <allow-from http-request-headers="*">
        <domain uri="http://intranet.mydomain.net"/>
      </allow-from>
      <grant-to>
        <resource path="/ServiceB/" include-subpaths="true"/>
      </grant-to>
    </policy>
  </cross-domain-access>
</access-policy>

这篇关于Silverlight WCF服务跨域问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆