如何从根目录访问WCF服务的客户端访问策略操作? [英] How can I get my WCF service's client access policy operation to be accessible from the root?

查看:177
本文介绍了如何从根目录访问WCF服务的客户端访问策略操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以通过以下操作在WCF服务中托管客户端访问策略:

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);
}

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

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

在IE中浏览时,我得到一个404.但是,如果我浏览到这里,则可以找到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)?

推荐答案

我猜测您没有使用IIS来承载服务,因为您试图通过WCF调用返回clientaccesspolicy.xml.

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.

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

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.

这篇关于如何从根目录访问WCF服务的客户端访问策略操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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