4
votes

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?

10

10 Answers

7
votes

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

2
votes

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

1
votes

Some debugging techniques available via a webcast I did that attempted to demonstrate some of the techniques I wrote about: https://www.livemeeting.com/cc/mseventsbmo/view?id=1032386656&role=attend&pw=F3D2F263

1
votes

Don't know if your issue is the same but I've just blogged about the major pain I had this weekend trying to get cross-domain happening with my SL app talking to my Console hosted WCF service.

http://wallism.wordpress.com/2009/03/01/silverlight-communication-exception/

In a nutshell though, you must have a crossdomain.xml and don't have 'headers="*"'

Bad:
    <allow-access-from domain=""*"" headers="*" />

Good:
    <allow-access-from domain=""*"" />
    <allow-http-request-headers-from domain=""*"" headers=""*"" />

Instead of * for headers you can have "SOAPAction" (work's either way)

Oh and when you do get it working you may want to make it a bit more secure :-)

Good luck!

0
votes

I'd start by making sure Silverlight is actually finding your client access policy file by inspecting the network calls using Fiddler, FireBug, or a similar tool.

0
votes

If you are using a WCF service at the same location the Silverlight app was served from you don't need a cross domain policy. I have had similar errors when returning LINQ to SQL data from the client where there was a relation between multiple entities.

First make sure you WCF service is working properly. Do this by creating a simple ping function that just echos its input. Make sure you can call this first. If this works and your other function doesn't its something, either with the parameters or return of the function. If the first function also fails use a tool like Fiddler to see what data is send over the wire. Use a . at the end of the host to see the data from localhost. So something like http//localhost:1234./default.aspx and use the same for the WCF address.

0
votes

i have same problem. I do see that clientaccesspolicy.xml is fetched by silverlight client app successfully. I did ensure clientaccesspolicy.xml is not malformed by requesting it directly via firefox. The policy is wide open, same as the one above.

Now here comes the bizarre twist. If I remove clientaccesspolicy.xml and instead add the Flash style crossdomain.xml policy file then it works. I do see through inspecting the network, how clientaccesspolicy.xml is requested first unsuccessfully and then silverlight falls back to crossdomain.xml.

So I do have a work around, but I prefer making clientaccesspolicy.xml work so that there is no additional unneeded network round trip.

Any suggestions?

0
votes

I found the book, Data-Driven Services with Silverlight 2 by John Papa to go over this extensively. I had the same issues and this excellent book explains it all.

0
votes

Make sure Endpoints and Binding of WCF service are defined correctly. To call WCF service from same application does not need cross domain policy file.

0
votes

I had a similar problem and removing the service reference and adding it back again solved the problem for me.