Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling WCF Service from Silverlight

Im calling a locally hosted wcf service from silverlight and I get the exception below.

Iv created a clientaccesspolicy.xml, which is situated in the route of my host.

<?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>

An error occurred while trying to make a request to URI 'http://localhost:8005/Service1.svc'. This could be due to a cross domain configuration error. Please see the inner exception for more details. --->

{System.Security.SecurityException ---> System.Security.SecurityException: Security error. at MS.Internal.InternalWebRequest.Send() at System.Net.BrowserHttpWebRequest.BeginGetResponseImplementation() at System.Net.BrowserHttpWebRequest.InternalBeginGetResponse(AsyncCallback callback, Object state) at System.Net.AsyncHelper.<>c__DisplayClass4.b__3(Object sendState) --- End of inner exception stack trace --- at System.Net.AsyncHelper.BeginOnUI(BeginMethod beginMethod, AsyncCallback callback, Object state) at System.Net.BrowserHttpWebRequest.BeginGetResponse(AsyncCallback callback, Object state) at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.CompleteSend(IAsyncResult result) at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.OnSend(IAsyncResult result)}

Any ideas on how to progress?

like image 815
Dan Avatar asked Dec 23 '22 14:12

Dan


2 Answers

there are some debugging techniques listed here..one more useful post..

like image 104
Gulzar Nazim Avatar answered Jan 03 '23 20:01

Gulzar Nazim


I know the service is working correctly, because I added it as a reference to a basic website and it worked. I'll try to play with Fiddler, although there is a slight issue as the xaml control is not embedded into a web page, its using the inbuilt testpage renderer.

Here is a few pointers that iv found that need to be checked:

Adding a clientaccesspolicy.xml as a shown my question.

Adding a crossdomain.xml to the host route:

<!DOCTYPE cross-domain-policy SYSTEM "http://www.adobe.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
  <allow-http-request-headers-from domain="*" headers="*"/>
</cross-domain-policy>

Ensure binding is basicHttp as this is the only one supported by silverlight(currently)

The service needs this attribute:

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] 

Useful reads: http://weblogs.asp.net/tolgakoseoglu/archive/2008/03/18/silverlight-2-0-and-wcf.aspx

http://timheuer.com/blog/archive/2008/06/06/changes-to-accessing-services-in-silverlight-2-beta-2.aspx

http://silverlight.net/forums/t/19191.aspx

http://timheuer.com/blog/archive/2008/04/09/silverlight-cannot-access-web-service.aspx

like image 38
Dan Avatar answered Jan 03 '23 22:01

Dan