user1567453
user1567453

Reputation: 2095

Silverlight 4 Project - Web Request.GetResponse Not Available

I am having trouble with my HttpWebRequest type. I am trying to use HttpWebRequest.GetResponse() and it doesn't seem to exist on my HttpWebRequest object. I have this code in my silverlight project:

HttpWebRequest req1 = WebRequest.Create(MyUrlString) as HttpWebRequest;
req1.Method = "Get";
req1.ContentType = "text/xml";
req1.Accept = "application/xml";

using (HttpWebResponse resp = req1.GetResponse() as HttpWebResponse) 
{

}

Can anyone tell me why "req1.GetResponse()" is not valid c# code? I've been seeing it used a lot of times on my searches in google for how to do this however I can't get it to work for me.

Upvotes: 0

Views: 500

Answers (1)

ppiotrowicz
ppiotrowicz

Reputation: 4614

It's not valid because it's synchronous. Silverlight team made the decision to use only asynchronous network calls, because it's better for overall user experience (application is more responsive when UI thread is not blocked).

You should use BeginGetResponse which is asynchronous.

Upvotes: 1

Related Questions