Deciding between HttpClient and WebClient

后端 未结 6 1229
情话喂你
情话喂你 2020-11-22 14:37

Our web app is running in .Net Framework 4.0. The UI calls controller methods through ajax calls.

We need to consume REST service from our vendor. I am evaluating

6条回答
  •  清酒与你
    2020-11-22 15:35

    HttpClient is the newer of the APIs and it has the benefits of

    • has a good async programming model
    • being worked on by Henrik F Nielson who is basically one of the inventors of HTTP, and he designed the API so it is easy for you to follow the HTTP standard, e.g. generating standards-compliant headers
    • is in the .Net framework 4.5, so it has some guaranteed level of support for the forseeable future
    • also has the xcopyable/portable-framework version of the library if you want to use it on other platforms - .Net 4.0, Windows Phone etc.

    If you are writing a web service which is making REST calls to other web services, you should want to be using an async programming model for all your REST calls, so that you don't hit thread starvation. You probably also want to use the newest C# compiler which has async/await support.

    Note: It isn't more performant AFAIK. It's probably somewhat similarly performant if you create a fair test.

提交回复
热议问题