How can I get my WCF service's client access policy operation to be accessible from the root?

时光毁灭记忆、已成空白 提交于 2019-12-13 02:19:00

问题


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)?


回答1:


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.



来源:https://stackoverflow.com/questions/3040424/how-can-i-get-my-wcf-services-client-access-policy-operation-to-be-accessible-f

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!