次の方法で共有


Cross Domain : Trouble while accessing Web Services

When Silverlight attempts to access a Web Service, if the SOO is different from the Web Service host, you have to deal with a cross domain issue. This issue can occur in various scenarios as described in Silverlight scenarios for Rich Internet Applications

The issue can be treated as follow :

1. I am encountering a ProtocolException

image

  • Reason

    Silverlight is attempting to access a Web Service which is across its own domain boundaries. For security reasons, a policy file must exist at the root of the Web Service host. It allows this cross-domain access : it’s either clientaccesspolicy.xml or crossdomain.xml files which were not found by Silverlight.

    image 

2. Even if the clientaccesspolicy.xml is found, my Silverlight application access the service

  • Reason

    Indeed, the clientaccesspolicy.xml file is here but is not accepted by the Silverlight application : there is some missing information. 

    image

    There has been some modifications since Silverlight 2 beta 2 : Ensure that ‘http-request-headers’ attribute is correctly set in ‘allow-from’ element in the clientaccesspolicy.xml file. See below for a basic and working policy file :

 <?xml version="1.0" encoding="UTF-8"?>
 <access-policy>
     <cross-domain-access>
         <policy>
             <allow-from http-request-headers="*">
                 <domain uri="*"/>
             </allow-from>
             <grant-to>
                 <resource include-subpaths="true" path="/"/>
             </grant-to>
         </policy>
     </cross-domain-access>
 </access-policy>

More information can be found at

https://msdn.microsoft.com/en-us/library/cc197955(VS.95).aspx

- Ronny Kwon

Comments

  • Anonymous
    August 05, 2008
    The How-To series demo Silverlight accessing Web Services in various configuration. In this post, we

  • Anonymous
    August 05, 2008
    The HowTo serie demoes Silverlight accessing Web Services in various configurations. In this post, we

  • Anonymous
    August 11, 2008
    This tip concerns those who wants to use self hosting capabilities of services in WCF or Restlet in cross-domain