Wcf – Silverlight WCF issue with cross-domain policy file

silverlight-4.0wcf

Ive seen a number of threads on this issue but none have worked for me. I have a simple silverlight application. I consume a WCF service. When I call a method GetOrderList from the service I get the following error:

An error occurred while trying to make a request to URI 'https://testserver2.mydomain.org/ORDERNET/WCFServices/OrderService/OrderService.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.

Here is my code:

public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
            ServiceReference1.ServiceClient sc = new ServiceReference1.ServiceClient();
            sc.GetOrderListAsync("testuser");
            sc.GetOrderListCompleted += new EventHandler<ServiceReference1.GetOrderListCompletedEventArgs>(sc_GetOrderListCompleted);
        }

        void sc_GetOrderListCompleted(object sender, ServiceReference1.GetOrderListCompletedEventArgs e)
        {
            var RESULT = e.Result;
        }
    }

This is my client access policy file that I put on my wwwroot:

<?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 path="/" include-subpaths="true"/>  
      </grant-to>  
    </policy>  
  </cross-domain-access>  
</access-policy> 

When I run fiddler, it finds the "clientaccesspolicy.xml" with a 200 OK (text/xml) so I know is finding the file.

What could be the issue? Do I have an invalid policy file? If I create a console application and consume the service, I can call the method with thno problem.

Any ideas?

Best Answer

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

Silverlight Cross Domain Web Service Access Error - This could be due to attempting to access a service in a cross-domain way without a proper cross-domain policy in place

thanks.....

Related Topic