Sunday 15 September 2013

c# - Async Get in ASP.net Web API does not close the connection when there is a GetResponseAsync in it -


Here is my code:

  public Async Task & lt; HTTPRPS Pormes & gt; () {Var url = "Here are some URLs"; String content; HttpWebRequest request = WebRequest.Create (url) as HttpWebRequest; / * 1 * / using (HttpWebResponse WebResponse = wait request.GetResponseAsync () HttpWebResponse AS) (StreamReader using {reader = new StreamReader (webresponse.GetResponseStream ())) {/ * 2 * / content = wait Reader.ReadToEndAsync (); }} Var response = this.Request.CreateResponse (HttpStatusCode.OK); reaction. Content = new string content (content, encoding. UTF8, "text / plain"); Return feedback; }  

And my problem:

I try to visit to get my IE, connected all the time is pending and has not shown anything Has been marked as. In Firefox, I can read a part of the data, and probably remembers some characters shown some Knk mark with tabs.

I think it is not locked by me because the HTTP connection is not expressed by IIS (and flushed with some characters).

I tried to modify my code in line 1 and 2. If I have a synchronous call change result in line code request. GetResponse () as HttpWebResponse everything works fine I work as expected, no mater what line in 2, ReadtoEnd () , async or sync.

I can use one of the alternatives that only request.GetResponse () the phone does everything, but I want to know why this would happen.


No comments:

Post a Comment