I’m working on a Silverlight application that makes calls to WCF services to work with data, and today I ran into this error:
System.ServiceModel.CommunicationException: An error occurred while trying to make a request to URI ‘http://SharePointDev:4444/_wcf/WCF_Services.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.
—> System.Security.SecurityException —> System.Security.SecurityException: Security error.
I remembered I had this issue some time ago and nonetheless I didn’t remember what the problem was or what the solution was, even thought the error is self explanatory…
So after wasting time researching I found on the internet the solution, so this time I’m writing about it for my records. Dang! I’m a 25 year old with a memory of a 60 year old (with all the respect for the 60 year old people out there …) hehe, I don’t like to waste time on these little errors, specially when I’m as busy as today.
Anyway, the solution is the “clientaccesspolicy.xml” file. The error has to do with the cross-domain policy. We have to explicitly grant cross domain access to Silverlight (even if you are working with local apps), and the way to do it is by adding the “clientaccesspolicy.xml” file to the root level of the WCF service.
Since my WCF is hosted in SharePoint and it is using a virtual path, Silverlight was looking for the file at the root level and not at the virtual path level, so you also have to take this in consideration. This is the blog that helped me with this issue for a better reference