问题
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