Are there any drawbacks to building a .NET REST client using HttpWebRequest / Response

I want to create a .NET REST client using C #, and although I've read a lot of posts about common REST-related techniques, I couldn't be sure of anything. I've read many examples of REST clients and most of them only used the HttpWebRequest / Response classes to send requests and receive responses. I want to ask what you think the disadvantages would be if I use REST services in this way. I haven't used WCF yet, and I don't have a big idea about this either, so I can't do the comparison myself.

Using this REST client, I am receiving, updating and sending some data to the device. So, apart from ease or complexity of development, my biggest issue is performance. Do you think the HttpClient in WCF makes sense?

thanks in advance..

+2


source to share


2 answers


The HttpClient in the WCF REST Starter Kit is based on HttpWebRequest and HttpWebResponse. The only dependency it has in WCF is the HttpContent extension methods, which are in the Dll extension.

I would recommend using Microsoft.Http.HttpClient because it adds a HUGE amount of functionality to properly execute HTTP. All HTTP headers are wrapped. The HttpContent class takes care of reading and writing from the Request and Response stream. It will buffer the response so you can read the response multiple times. It has support to make asynchronous calls much easier.



If you follow the pattern of using extension methods to convert to your own data formats, you will find that the library is very easy to work with.

+3


source


I don't think there will be significant performance differences. However, you will end up with complex code just by using HttpWebRequest and Response. For small applications this will be fine, but for more advanced tasks you will quickly end up with unreachable code. With this primitive approach, you will need to implement the REST philosophy yourself. In contrast, WCF is ready for you and you only need to focus on your application.



-1


source







All Articles