如何才能从根访问我的 WCF 服务的客户端访问策略操作?
我有以下操作来在 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 应用程序连接到我的服务时,我收到错误,因为它找不到客户端访问策略。它在这里寻找它:
当我在 IE 中浏览时,我收到 404。但是,我如果我浏览到此处,可以找到 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:
When I browse there in IE, I get a 404. However, I can find the clientaccesspolicy.xml file if I browse to here:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我猜测您没有使用 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 ofhttp://localhost
where your main service would have a base address ofhttp://localhost/server
.