1

I'm writing a Silverlight application that needs to interface with a server via GET/POST requests. My code looks like the following:

Uri serviceUri = new Uri(my_URI);
WebClient client = new WebClient();

client.OpenReadCompleted += new OpenReadCompletedEventHandler(OnRequestComplete);
client.OpenReadAsync(serviceUri);

However, when the callback function is called, I am getting a System.Security.SecurityException. I've read multiple questions on here from people with similar errors, however all of their issues seem to stem from cross domain issues while debugging. When I run my code, it runs with http://localhost:... as the domain, so that shouldn't be the issue I don't think. Here's the full error if that helps at all:

{System.Security.SecurityException: Security error.
   at System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)
   at System.Net.Browser.BrowserHttpWebRequest.<>c__DisplayClassa.<EndGetResponse>b__9(Object sendState)
   at System.Net.Browser.AsyncHelper.<>c__DisplayClass4.<BeginOnUI>b__0(Object sendState)}

Thanks for any help. This has been a very frustrating issue.

UPDATE:

I screwed around with it a lot and eventually got everything to work. Not 100% what did it though... I ended up copy/pasting the clientaccesspolicy.xml and crossdomain.xml files everywhere imaginable, created a new Silverlight project and copied everything there, along with a few other things. If anyone else runs into this problem, that's about as much advice as I have to give :/

2
  • Possible duplicate of stackoverflow.com/questions/766574/… Commented Apr 24, 2013 at 5:49
  • He's running from a file:// URI. Like I stated above, I'm running from localhost Commented Apr 24, 2013 at 5:53

1 Answer 1

1

I think it is still violates same-origin policy because the port numbers don't match: i.e. the XAP uri's port and the my_URI port do not match. And hence the System.Security.SecurityException. Could you try hosting the my_URI relative to your XAP.

Or even better, can you try interacting with the server using WCF.

Sign up to request clarification or add additional context in comments.

1 Comment

Interesting. I wrote a quick little C# app to test out sending and receiving requests and that seemed to work. Assuming this still is a same-origin issue, how would I go about solving it? I've already tried all (reasonable) suggestions I found online such as adding the clientaccesspolicy.xml and crossdomain.xml

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.