views:

45

answers:

3

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>
         <allow-from http-request-headers="SOAPAction"> 
          <domain uri="http://*"/&gt; 
          <domain uri="https://*" />  
         </allow-from>
        <grant-to>
           <resource include-subpaths="true" path="/"/>
        </grant-to> 
       </policy>
     </cross-domain-access>
  </access-policy>

Any ideas?

+1  A: 

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.

Mike
Thanks @Mike, I have installed fidler now and am have seen it looking for the clientaccesspolicy.xml in "localhost:8732", I have tried adding the file into "C:\inetpub\wwwroot" but am having no luck. Is that where i need to put the file? (sorry, i'm fairly new to web dev)
Ben
Thanks @Mike,Fiddler debugger is really great for web developers
Ramakrishnan
+3  A: 
<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd"&gt;
<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.

Ardman
A: 

Hi,

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.

Mike