niklassaers
niklassaers

Reputation: 8810

Loading data from a site in Silverlight

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

Upvotes: 1

Views: 223

Answers (1)

Dave Swersky
Dave Swersky

Reputation: 34810

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.

Upvotes: 2

Related Questions