Saturday, January 30, 2010

Enabling cross-domain calls for Silverlight apps on WCF

The problem

In my Silverlight application, it try to call a WCF web service hosted on the web server (IIS). When i run the Silverlight application, the follow exception was obtain:
“An error occurred while trying to make a request to URI 'http://myserver/myservicehost/service1.svc'. 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. This error may also be caused by using internal types in the web service proxy without using the InternalsVisibleToAttribute attribute. Please see the inner exception for more details.”

Resolve

Create follow two xml files and add into C:\inetpub\wwwroot folder.
ClientAccessPolicy.xml
<?xml version="1.0" encoding="utf-8"?>

 
  
   
    
   
   
    
   
  
 

CrossDomain.xml

 
 

Notice: You have to restart IIS and redeploy WCF service before using in Silverlight.