Silverlight 4 WCF "Cross-Domain" error
We have a WCF service running on a remote server. It runs as a Windows Service, not hosted in IIS. We can hit this WCF service from our WinForms and WFP apps without any problem. However, when we attempt to hit it from a Silverlight 4 app, we get the following error:
An error occurred while trying to make a request to URI 'http://111.111.111.111/8484/Psn'. 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-re开发者_如何学Clated 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.
Could someone put this into English and explain what I might be able to do to satisfy Silverlight?
The first thing to check is that you have a clientaccesspolicy.xml
file or crossdomain.xml
file on the WCF service host. Either of these files can be used to control which domains have access to your service. Without them no one has any access from Silverlight. These files live in the root of the WCF service host:
If, for example, the service is hosted in http://fabrikam.com then the file must be located at http://fabrikam.com/clientaccesspolicy.xml ... [or] ... http://fabrikam.com/crossdomain.xml.
The following clientaccesspolicy.xml
file will allow access from http://www.example.com
but block it from everywhere else:
<?xml version="1.0" encoding="utf-8"?>
<access-policy>
<cross-domain-access>
<policy>
<allow-from http-request-headers="SOAPAction">
<domain uri="http://www.example.com"/>
</allow-from>
<grant-to>
<resource path="/" include-subpaths="true"/>
</grant-to>
</policy>
</cross-domain-access>
</access-policy>
A similar crossdomain.xml
file would be:
<?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="http://www.example.com" headers="SOAPAction,Content-Type"/>
</cross-domain-policy>
Source
精彩评论