Silverlight 应用程序的 WCF

发布于 2024-07-22 14:24:34 字数 262 浏览 6 评论 0原文

我创建了一个使用 WCF 服务的 Silverlight 2 应用程序。 该服务位于本地文件夹(不是 IIS)中,并且可以在 Winforms 测试中正常工作。 当我尝试调用该服务时,它返回错误:“跨域没有策略”。

我尝试将 clientaccesspolicy.xml 和 crossdomain.xml 添加到: wcf 项目文件夹 iis wwwroot 本地驱动器根目录 E:\

但没有任何影响 我应该把它们放在哪里?

I have created a Silverlight 2 appliction, that uses a WCF service.
The service is located in a local folder (not IIS) and works fine with a Winforms test.
when I try to call the service, it returns with an error: " no pocily for cross domain".

I've tryed to add clientaccesspolicy.xml and crossdomain.xml to:
the wcf project folder
the iis wwwroot
the local drive root E:\

but nothing takes any affect
where should i put them?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

明明#如月 2024-07-29 14:24:34

正如您所说,您没有在 IIS 下运行该服务,我将做出一些假设

  • 您的 silverlight 应用程序托管在一个 html 页面中,您可以通过双击加载,在浏览器位置栏中给出 file:// URI,或者您正在将其发布到本地 IIS。
  • 您的 WCF 服务正在某些自托管进程中运行,例如命令行应用程序、Windows 服务或 Winforms 应用程序。 无论它通过什么方式托管,都不会与您的 silverlight 应用程序位于同一 URL 上。

silverlight 应用程序和 wcf 服务托管在单独的 url 中,应用程序位于 file://example.html 或 http://localhost 如果您已将其发布到 http://localhost:1234 上的 IIS 和 wcf 服务。 这会引发跨域访问问题,因为端口号不同,或者您从 file:// URI 加载 silverlight 应用程序并且您自行托管 WCF 服务。 如果您自行托管 WCF 服务,则无法解决此问题,因为它们需要 clientaccesspolicy.xml 文件或 crossdomain.xml 文件,允许从 silverlight URL 访问服务,但是无法从根目录提供 XML自托管 WCF 服务器。

As you say you don't have the service running under IIS I am going to make some assumptions

  • Your silverlight app is hosted in an html page you load by double clicking, giving a file:// URI in the browser location bar, or you're publishing it to your local IIS.
  • Your WCF service is running in some self hosted process like a command line app, windows service or Winforms application. Whatever it is hosted through it will not be on the same URL as your silverlight app.

The silverlight app and the wcf service are hosted in separate urls, the app on file://example.html or http://localhost if you've published it to IIS and the wcf service on http://localhost:1234. This raises cross domain access problems because the port numbers are different, or you are loading the silverlight app from a file:// URI and you're self hosting the WCF service. If you are self hosting the WCF service you cannot solve this because they require either a clientaccesspolicy.xml file or a crossdomain.xml file allowing access to the services from your silverlight URL, however there is no way to serve an XML from the root of the self hosting WCF server.

一枫情书 2024-07-29 14:24:34

如果您要从 http://... 上下文转到 file://... 上下文,实际上这不是跨域问题。 相反,这是一个跨上下文问题,出于安全原因,Silverlight 2 中不允许这样做(http:// 和 https:// 也会发生这种情况)。 我不确定 Silverlight 3 中会是什么状态。

If you're going from an http://... context to a file://... context, it's not a cross-domain issue, actually. Instead, it's a cross-context issue, which is not allowed in Silverlight 2 (this also happens with http:// and https://) for security reasons. I'm not sure what the state of this will be in Silverlight 3.

活雷疯 2024-07-29 14:24:34

也许您之后没有重新启动 IIS?

编辑:这是一个完整的教程,请确保您没有执行每一步以使其正常工作:Silverlight 2.0 和 WCF

Perhaps you didn't restart IIS after that?

Edit : Here's a thorough tutorial, make sure you've don't every step to make it work : Silverlight 2.0 and WCF.

一杯敬自由 2024-07-29 14:24:34

嗯...使用 fiddler 检查 clientaccesspolicy.xml 请求是否已发送。

另一方面,一个虚拟的客户端访问策略来检查连接是否正常工作:

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

但是,您应该尝试在同一个域上工作(如果您需要呼叫的安全性,那就更好了)。

Mm... check using fiddler if the clientaccesspolicy.xml request is sent.

On the other hand, a dummy clientaccesspolicy to check if the connection is working:

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

But, you should try to work on the same domain (better if you need security on your calls).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文