The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

54408 (6) [Avatar] Offline
#1
Great book, the only thing that seems wrong to me is the use of a disposed HttpClient in the example code.
using (var client = new HttpClient()) {
}

From the documentation for HttpClient:
HttpClient is intended to be instantiated once and re-used throughout the life of an application. Instantiating an HttpClient class for every request will exhaust the number of sockets available under heavy loads. This will result in SocketException errors. Below is an example using HttpClient correctly


See: https://msdn.microsoft.com/en-us/library/system.net.http.httpclient(v=vs.110).aspx for the full documentation.

There is a good write up on what happens if you don't use a static HttpClient for your application at https://aspnetmonsters.com/2016/08/2016-08-27-httpclientwrong

Is there a reason that you don't use a static HttpClient in your examples?


Dustin Metzgar (26) [Avatar] Offline
#2
No, it's just a total miss on my part. Thanks for pointing this out! The book is currently in production but I'll see if we can get the examples fixed.