views:

48

answers:

1

Hi, I'm trying to load data into my Silverlight app. However, when it launches, I get a TargetInvocationException as soon as I hit e.Result:

public MainPage() {
  WebClient wc = new WebClient();
  wc.OpenReadCompleted += new OpenReadCompletedEventHandler(wc_OpenReadCompleted);
  wc.OpenReadAsync(new Uri("http://www.google.com"));
}

void wc_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e) {
  Stream st = e.Result;
  StreamReader sr = new StreamReader(st);
  String result = sr.ReadToEnd();
}

Why does this fail, and what should I do to make it work?

PS, I'm afraid I cannot make a local proxy, because the app is going to be deployed as part of an app on an Apache Tomcat server, not an IIS.

Cheers

Nik

+2  A: 

Silverlight cannot make cross-domain requests without a cross-domain policy file on the target domain. If you can't set up a proxy, you won't be able to get data from any domain other than the one hosting your application.

Dave Swersky
I have full control over the domain and server where the webservice is hosted, so this is not a problem. Any pointers to how I can host a cross-domain policy on a Tomcat server? Anything I shold be especially aware of with a Silverlight app and a cross-domain policy on a Tomcat server?
niklassaers
The policy file is crossdomain.xml. I think it has to be available at the root, nothing else special about it. IIS, Tomcat, Apache, hosting platform shouldn't matter.
Dave Swersky