Why is there both a System.Net.Http and System.Web.Http namespace?

后端 未结 5 1396
渐次进展
渐次进展 2021-01-31 01:34

Just a simple question as I\'m studying the various class libraries available in .NET. I noticed that there\'s a System.Net.Http namespace and a System.Web.H

相关标签:
5条回答
  • 2021-01-31 02:08

    "System.Web.Http" is used for creating WebAPIs.

    "System.Net.Http" is used for consuming WebAPIs (using HttpClient class)

    0 讨论(0)
  • 2021-01-31 02:11

    System.Web heavily depends on IIS web server, which can only be hosted on a Windows machine. As Microsoft is heading to open source and is starting to support multiple platforms like Linux and Mac, they need to extract their functionality which will be independent of IIS server. As a result, System.Net is independent of IIS features and is deployable to different platforms.

    0 讨论(0)
  • 2021-01-31 02:20

    System.Net.Http is for client-side HTTP programming. System.Web.Http is for server-side HTTP programming.

    0 讨论(0)
  • 2021-01-31 02:22

    From my experience, the separation between the two namespaces becomes clear when you look at the difference between self hosted webapi services vs IIS-hosted. Self hosted only requires System.Http, whilst IIS hosted needs both. See Difference between "MapHttpRoute" and "MapRoute"? for a similar discussion and useful links.

    So, the reason there are two is so that you can create a self-hosted web service that doesn't depend on the entire ASP.NET stack.

    Neither of them are deprecated.

    I haven't seen an official Microsoft explanation for this, but that's the best I've been able to find.

    0 讨论(0)
  • 2021-01-31 02:30

    System.Net.Http relates to network programming while System.Web.Http relates specifically to programming for the web.

    0 讨论(0)
提交回复
热议问题