This project is read-only.

HttpClient disposable?

Topics: Web Api
Jan 24, 2011 at 9:00 AM

With the "old world" WebClient based requests you needed to be very careful about disposing of responses and streams. All the examples I've seen of using HttpClient have no protection whatsoever. Could someone comment on what is best practice for using/disposing of the new HttpClient?


Jan 24, 2011 at 9:52 AM

Hi Andy

Yes you are correct. The client, and the messages which are exchanged should be properly disposed. Calling dispose on the Request / Response calls dispose on the Content which releases the underlying streams. We will update the samples.


Jan 24, 2011 at 9:55 AM

BTW, if the new HttpRequestMessage / HttpResponseMessage are accessed as parameters on a service, they do not have to be disposed as we will dispose them.