WCF and Silverlight CrossDomain.xml
Apologies if this has been asked before (I couldn't find the answer anywhere), but I have a WCF Service Application that I have created, and am trying to access via my Silverlight 4 app. I have added the service reference to the SilverLight App and am just trying to call one of the default pre existing methods on the service (GetData). When calling the method i get an error of:
An error occurred while trying to make a request to URI "my URI" This could be due to attempting to access a service in a cross-domain way without a proper cross-domain policy in place, or a policy file that is unsuitable for SOAP Services.
I'm aware I need a crossdomain.xml file, but it doesnt seem to matter where i place the crossdomain.xml file, i still get the error, this is the contents of the file:
<?xml version="1.0" encoding="utf-8"?>
<access-policy>
<cross-domain-access>
<policy开发者_如何学C>
<allow-from http-request-headers="SOAPAction">
<domain uri="http://*"/>
<domain uri="https://*" />
</allow-from>
<grant-to>
<resource include-subpaths="true" path="/"/>
</grant-to>
</policy>
</cross-domain-access>
</access-policy>
Any ideas?
It does matter where you place the policy file - it needs to be placed "at the root" of the web server that's running your service.
That's pretty well documented up at http://msdn.microsoft.com/en-us/library/cc197955(VS.95).aspx
My best advice on these issues is to run the Fiddler tool and trace the traffic and you should see Silverlight looking for a clientaccesspolicy.xml file (and also the crossdomain.xml file which is a different format) and that should make it easier to determine where Silverlight is looking for the file.
Mike.
<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<allow-http-request-headers-from domain="*" headers="*"/>
</cross-domain-policy>
Here is a very simple crossdomain.xml
file. Compared to yours, it appears that you have written a clientaccesspolicy.xml
file. Rename the file to clientaccesspolicy.xml
and you should be fine.
Firstly, does this video help at all? http://channel9.msdn.com/posts/mtaulty/Silverlight-4-Beta-Networking-Part-4-Cross-Domain-HTTP/
Secondly - the way I diagnose these is as follows;
1) I use Fiddler to make sure that I see Silverlight REQUEST a clientaccesspolicy.xml file and that it GETS the clientaccesspolicy.xml - i.e. check that your web server is returning clientaccesspolicy.xml and silverlight is not getting a "NotFound" status back to its request. You can see that in Fiddler. BTW - you don't mention whether you're using IIS or Cassini? IIRC "localhost" can present a few problems to fiddler so I usually use IIS and a proper machine name.
2) When I know that Silverlight is definitely getting a clientaccesspolicy.xml file what I then do is generally build the most relaxed version of the file I can think of. Something like;
and once I'm happy that this works I then refine the list of domains, paths, headers and methods down to what I actually need.
Hope that helps.
Mike.
精彩评论