Wcf – Silverlight accessing WCF serivce throws Crossdomain error

clientaccesspolicy.xmlcrossdomain.xmliis-7silverlightwcf

I understand this question has been answered many times but i could not resolve it for some reason. I hope some one can solve my problem which might be straightforward for many, but i some how couldnt figure it out as I am relatively new to silverlight and web. I have tried all the possible samples available in the internet on cross domain errors but couldnt fix it. I appreciate if any once can help me on this issue i am facing.

I am accessing WCF service from Silverlight 4 client. I have Clientacccesspolicy.xml and Crossdomain.xml in the wwwroot.

I can access my file by using [http://localhost/Remoteapp.html]. But i am getting cross domain error inspite of having the Clientaccesspolicy.xml file in the root, when the application tries to make a webservice call.

In the webdevelopementhelper i can see that the clientaccesspolicy is being requested at the wcfservice port which is [http//localhost:600061/clientaccesspolicy.xml], which is where my service is located and i am getting a 502 response[Connection failed].

When I type [http://localhost/Clientaccesspolicy.xml] in the browser i can locate the file. But silverlight is requesting the policy file at a wrong location.

Every thing works properly in the design time, but when i deploy it to IIS i am getting this error.

Can any one help me how to resolve this issue? Thanks to every one in advance.

Best Answer

Step 1: check that you have a clientaccesspolicy.xml file or crossdomain.xml file on the WCF service host.

The following clientaccesspolicy.xml

<?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>

A similar crossdomain.xml file would be:

<?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>

if that does not work, try these steps

  1. On the server where the silver light application is deployed , typically in the ClientBin folder of the ASP.NET application, rename the silverlight application file *.xap to *.zip

  2. Extract the contents of the zip file

  3. Edit the ServiceReferences.ClientConfig file

  4. Update the end point address from localhost to the server address where the WCF service is hosted.

  5. Save the file. Zip the contents and rename back to .xap

Related Topic