如何才能从根访问我的 WCF 服务的客户端访问策略操作?

发布于 2024-09-05 10:46:12 字数 966 浏览 2 评论 0原文

我有以下操作来在 WCF 服务中托管我的客户端访问策略:

[OperationContract]
[WebGet(UriTemplate = "/clientaccesspolicy.xml")]
XElement RetrieveClientAccessPolicy();

public XElement RetrieveClientAccessPolicy()
{
    String policy = @"<?xml version=""1.0"" encoding=""utf-8""?>
                    <access-policy>
                        ...
                    </access-policy>";

    return XElement.Parse(policy);
}

当我尝试从 silverlight 应用程序连接到我的服务时,我收到错误,因为它找不到客户端访问策略。它在这里寻找它:

http://MyServer/clientaccesspolicy.xml

当我在 IE 中浏览时,我收到 404。但是,我如果我浏览到此处,可以找到 clientaccesspolicy.xml 文件:

http://MyServer/server/clientaccesspolicy.xml

如何获取我的操作以进行客户端访问策略文件可以从根目录访问,而不是从该目录访问(服务器是服务的名称)?

I have the following operation for hosting my client access policy in my WCF service:

[OperationContract]
[WebGet(UriTemplate = "/clientaccesspolicy.xml")]
XElement RetrieveClientAccessPolicy();

public XElement RetrieveClientAccessPolicy()
{
    String policy = @"<?xml version=""1.0"" encoding=""utf-8""?>
                    <access-policy>
                        ...
                    </access-policy>";

    return XElement.Parse(policy);
}

When I try to connect to my the service from my silverlight app, I get an error because it can't find the client access policy. It's looking for it here:

http://MyServer/clientaccesspolicy.xml

When I browse there in IE, I get a 404. However, I can find the clientaccesspolicy.xml file if I browse to here:

http://MyServer/server/clientaccesspolicy.xml

How can I get my operation to make the client access policy file accessible from the root, and not from that directory (server is the service's name)?

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

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

发布评论

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

评论(1

柏拉图鍀咏恒 2024-09-12 10:46:12

我猜测您没有使用 IIS 来托管服务,因为您尝试通过 WCF 调用返回 clientaccesspolicy.xml。

对于自托管 WCF 服务,我认为您必须为 App.config 中的 RetrieveClientAccessPolicy() 调用设置单独的服务端点和合同。该服务的基地址为 http://localhost,其中您的主服务的基地址为 http://localhost/server

I am guessing that you are not using IIS to host the service since you are trying to return the clientaccesspolicy.xml via a WCF call.

In the case of a self-hosted WCF service, I think you are going to have to set up a separate service endpoint and contract for your RetrieveClientAccessPolicy() call in your App.config. That service would have a baseAddress of http://localhost where your main service would have a base address of http://localhost/server.

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