I am building a simple HTTP file server.
I have an asp.net web application that exposes a WCF service (FileService.svc). The service contract is:[OperationContract]
[WebGet(UriTemplate = "/*")]
Stream HandleFileRequest();
The service implementation is quite straightforward and basically I use :
WebOperationContext.Current.IncomingRequest.UriTemplateMatch.RequestUri
To get the path of the file to return (A little parsing is required to extract it).
So for instance, when hosting the app locally on IIS , I can request a file from : http://localhost:65000/FileService.svc/someFolder1/someFolder2/someFile1.jpg
The problems starts when this request is made from inside a silverlight app. Silverlight searches the clientaccesspolicy file in http://localhost:65000/clientaccesspolicy.xml
The problem is that now, this request won't reach the service because FileService.svc is ommited from the url.(I want all the file requests to be handled by the WCF service in HandleFileRequest(), and not any other me开发者_高级运维chanism.)
One solution I can think of is to use the URL Rewrite module of IIS 7.
Is this the right way to do this, or there simpler solution to this ?The clientaccesspolicy.xml used by Silverlight has to be on the domain root - in your example that would mean http://localhost:65000/clientaccesspolicy.xml. The policy file is unique per domain, not per service. You can, however, set different policies for different services by adding one element for each service in the clientaccesspolicy.xml file, as shown in the example below.
<?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>
精彩评论