Tags

, , , , , ,

Hi, this is my first post in MVPWay !!!

Ok, this post is about a Silverlight Exception. That takes me at least 3 hours of my life😛.

What I was trying to do, is connect a Silverlight App to a WCF Web Service.

– Silverlight App, was executed by Visual Studio.

– WCF Web Service was published at my local IIS.

Visual Studio had no problems to add the service reference, but CommunicationException appears when I called a method.

System.ServiceModel.CommunicationException was unhandled by user code
An error occurred while trying to make a request to 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 that is unsuitable for SOAP services. You may need to contact the owner of the service to publish a cross-domain policy file and to ensure it allows SOAP-related HTTP headers to be sent. Please see the inner exception for more details.

What was the problem?
You have to Enable Cross Domain for Your WCF Service

How to solve it?
The way that I solved the problem, was:

– Create a XML with the code below and with the name: clientaccesspolicy.xml

 <?xml version="1.0" encoding="utf-8"?>
<access-policy>
  <cross-domain-access>
    <policy>
      <allow-from http-request-headers="*">
        uri="*"/>
      </allow-from>
      <grant-to>
        <resource path="/" include-subpaths="true"/>
      </grant-to>
    </policy>
  </cross-domain-access>
</access-policy>

– Copy clientaccesspolicy.xml, into the path of your IIS. In my case is:
C:\inetpub\wwwroot

Just this steps where enough for me.

If it wasn’t enough for you, maybe this link could help you:

4 Simple Steps to Consume WCF Service using Silverlight

Happy Coding, and feel free to comment.