Silverlight 在IIS上托管时,通过WCF Rest服务为clientaccesspolicy.xml提供服务

Silverlight 在IIS上托管时,通过WCF Rest服务为clientaccesspolicy.xml提供服务,silverlight,iis,wcf-rest,clientaccesspolicy.xml,Silverlight,Iis,Wcf Rest,Clientaccesspolicy.xml,我正在构建一个简单的HTTP文件服务器。 我有一个asp.net web应用程序,它公开了一个WCF服务FileService.svc。 服务合同为: [OperationContract] [WebGet(UriTemplate = "/*")] Stream HandleFileRequest(); 服务实现非常简单,基本上我使用: WebOperationContext.Current.IncomingRequest.UriTemplateMatch.RequestUri 要获取要返回

我正在构建一个简单的HTTP文件服务器。 我有一个asp.net web应用程序,它公开了一个WCF服务FileService.svc。 服务合同为:

[OperationContract]
[WebGet(UriTemplate = "/*")]
Stream HandleFileRequest();
服务实现非常简单,基本上我使用:

WebOperationContext.Current.IncomingRequest.UriTemplateMatch.RequestUri
要获取要返回的文件路径,需要进行一些解析以提取它

例如,当在IIS上本地托管应用程序时,我可以从以下位置请求文件:

当从silverlight应用程序内部发出此请求时,问题就开始了。Silverlight在中搜索clientaccesspolicy文件 问题是,现在这个请求不会到达服务,因为FileService.svc是从url发送的

我希望所有文件请求都由HandleFileRequest中的WCF服务处理,而不是任何其他机制

我能想到的一个解决方案是使用IIS7的URL重写模块。
这是正确的方法,还是有更简单的解决方案?

Silverlight使用的clientaccesspolicy.xml必须位于域根上——在您的示例中,这意味着。策略文件在每个域中是唯一的,而不是每个服务。但是,您可以通过在clientaccesspolicy.xml文件中为每个服务添加一个元素来为不同的服务设置不同的策略,如下例所示

<?xml version="1.0" encoding="utf-8"?> <access-policy> <cross-domain-access> <policy> <allow-from http-request-headers="*"> <domain uri="*"/> </allow-from> <grant-to> <resource path="/FileService.svc/" include-subpaths="true"/> </grant-to> </policy> <policy> <allow-from http-request-headers="*"> <domain uri="http://some.other.domain"/> </allow-from> <grant-to> <resource path="/AnotherService/" include-subpaths="true"/> </grant-to> </policy> </cross-domain-access> </access-policy>