Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top