Silverlight Cross Domain Web Service Access Error

2010-10-30


When you created WCF services, if you put your services on different severs in some case, just like me, for example: I created a WCF application which includes 2 web services, I deployed this WCF application onto 2 places, the one is on the server in my office, another one I put on my local laptop PC, the reason I put 2 copies of the WCF application to 2 different places is because I need to often modify one of the 2 web services, the another one I don't need to modify. I have also 2 other applications to consume those 2 web services, I set the service reference to my office one, set another service reference to my local pc one.

Then when I tried to run the solution, I got the cross domain web service access error:

An error occurred while trying to make a request to URI 'http://localhost:2128/myservicename.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.

The details explanation about this error please read here: Making a Service Available Across Domain Boundaries

For my case, I selected the simple one which looked like: create a crossdomain.xml file and I put it in the root folder of my WCF application, the content is:

<?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="SOAPAction,Content-Type"/>
</cross-domain-policy>

That is ! Everything is OK for me.