silverlight navigation project - problem with accessing an xml file in clientbin with a webservice
I'm trying to access my .xml file in the ClientBin with no success.
code:
WebClient xmlClient = new WebClient();
xmlClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(xmlClient_DownloadStringCompleted);
Uri uri = new Uri("Antwerpen1.xml", UriKind.RelativeOrAbsolute);
xmlClient.DownloadStringAsync(uri);
While debugging the uri throws the f开发者_JAVA技巧ollowing error: System.InvalidOperationException
The result throws the following error: This operation is not supported for a relative URI
I can access my file with the following path : http://localhost:2546/contentManagement.Web/ClientBin/Antwerpen1.xml
What am I doing wrong?
update: I tried the same code in the code behind of my main page and it worked. Still no result with the webservice.
update2: I found out it's not a problem of the URI but the xmlClient.DownloadStringAsync. The BaseAdress(path where the xml file in my clientbin is stored) is empty for some reason..
, ty in advance
You need to set up the client access policy for your web service to allow the service to work across domain boundaries.
The MSDN page has more details, but basically you need a file called clientaccesspolicy.xml
in the root directory of your web service which looks like this:
<?xml version="1.0" encoding="utf-8"?>
<access-policy>
<cross-domain-access>
<policy>
<allow-from http-request-headers="SOAPAction">
<domain uri="*"/>
</allow-from>
<grant-to>
<resource path="/" include-subpaths="true"/>
</grant-to>
</policy>
</cross-domain-access>
</access-policy>
This will allow anyone access. To lock it down replace the *
in the uri with your url.
精彩评论