Saturday, December 9, 2017

Difference between WebClient and HttpClient



I recently started learning and writing WebAPI services rather WCF REST services. 
While consuming WebAPI services, I learned the below differences between WebClient and HttpClient.




Web­Client


Http­Client
 Avail­able in older ver­sion of .NET  .NET 4.5 only. Cre­ated to sup­port the grow­ing need of the Web API REST calls
 WinRT appli­ca­tions can­not use WebClient  Http­Client can be used with WinRT
 Pro­vides progress report­ing for downloads.  No progress report­ing for downloads.
 Does not reuse resolved DNS, configured-cookies.  Can reuse resolved DNS, cookie con­fig­u­ra­tion, and other authentication.
 You need to new up a Web­Client to make the con­cur­rent request.  Sin­gle Http­Client can make con­cur­rent requests.
 Thin layer over WebRe­quest and WebResponse  Thin layer over Http­We­bRe­quest and HttpWebResponse
 Mock­ing and test­ing Web­Client is difficult  Mock­ing and test­ing Http­Client is easy
 Sup­ports FTP.  No sup­port for FTP.
 Both syn­chro­nous and Asyn­chro­nous meth­ods are avail­able for IO bound requests.  All IO bound meth­ods in HTTP­Client are asynchronous.




Refernces: http://www.diogonunes.com/blog/webclient-vs-httpclient-vs-httpwebrequest/ 
https://stackoverflow.com/a/27737601/405317

No comments:

Post a Comment