1
votes

I call a service from a Silverlight application and get the crossdomainploicy error. I put the clientaccesspolicy.xml in the same folder as the xap.file.

http://msdn.microsoft.com/en-us/library/cc197955%28v=vs.95%29.aspx

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

2

2 Answers

2
votes

The clientaccesspolicy.xml should be in the root folder of the domain hosting the service (e.g. http://mydomain.com/crossdomainpolicy.xml, not in the directory of the xap file.

It's clearly stated in the page you linked to:

Place a clientaccesspolicy.xml file at the root of the domain where the service is hosted to configure the service to allow cross-domain access.

0
votes

Did you make the webservice or are you using a third party webservice? The article you mentioned http://msdn.microsoft.com/en-us/library/cc197955%28v=vs.95%29.aspx is only applicable if you are the one that made the webservice.

What you are experiencing is a Site of Origin SOS error. If you are trying to use a third party webservice and they do not use a clientaccesspolicy you can get around this by creating a wrapper to the webservice. Basically you would have to create a webservice that you host at the same Site of Origin as your silverlight application. Your webservice would then make calls to the third party webservice and return values accordingly.

Because of the sandboxing security rules of Silverlight applications they can only communicate with webservices that are from the same Site of Origin unless the ClientAccessPolicy is applied to the webservice opening it up for outside Site of Origins to use. Again if you are not the one hosting the webservice you may not have any control over this.

SOS applies to host name, port, and protocol. So http://localhost/ is different from https://localhost/ and http://localhost:9999/ is different than http://localhost:80/