What are my options to consume a RESTful service using the .Net framework? When is WCF(using the WebChannelFactory) more preferable to HttpClient?
7 Answers
Microsoft`s newest HTTP library is here https://www.nuget.org/packages/Microsoft.Net.Http and I have a blog post showing how to use it here.
You would never want to use WebChannelFactory against a RESTful service. The coupling generated by WebChannelFactory defeats the point of REST.

- 139,164
- 32
- 194
- 243
-
Your blog link is dead, can you fix it? – dcp Oct 09 '13 at 00:08
-
@dcp Sorry about that. – Darrel Miller Oct 09 '13 at 01:42
-
1You'll want to see this package too: http://www.nuget.org/packages/Microsoft.Net.Http/ – Gilney Oct 25 '13 at 14:09
-
1Mentioned Nuget package is deprecated. It is better to add a link to this one: https://www.nuget.org/packages/Microsoft.Net.Http – Andriy Buday Sep 17 '15 at 11:09
-
@AndriyBuday Updated. Thanks. – Darrel Miller Sep 17 '15 at 15:14
Check out restsharp. I haven't used it, but am looking into it for consuming our own REST services.

- 2,979
- 2
- 21
- 32
-
How did this work out? Is restsharp a good choice? It looks super convenient and easy to use. – Jonathan Jan 31 '17 at 14:20
-
The hammock project makes it very easy to consume RESTful services, you can use it to easily create the required http requests you need:

- 14,796
- 2
- 33
- 41
There are few different ways of consuming REST services in .NET:
- Plain .NET HTTP request
- WCF mechanisms
- HttpClient (recommended, nuget package)
- Other libraries (RestSharp, Hammock, etc.)
I've wrote a blog post that demonstrates first three options.
As of consuming through WCF or HttpClient I think it makes sense to read this SO question to understand the potential of REST services. When you consume a REST service via WCF you cannot use all that power.

- 1
- 1

- 1,959
- 1
- 17
- 40
I think WCF is preferable whenever you want the abstraction it provides.
WCF provides an abstraction over the specific messaging and communication protocols being employed. Even only considering a RESTful scenario, you can more easily adapt to different message formats (XML, JSON, HTML).
WCF also provides configuration mechanisms, extensibility points, and instrumentation.

- 4,943
- 20
- 36
-
For anyone reading this now: WCF is essentially dead. Should you feel like looking into it, know that's it's a complete departure from REST, and should only be used if you really know you need it. – TheMonarch Jul 13 '17 at 16:15
-
@TheMonarch you seem to be under the impression that WCF is tied to a specific set of protocols. Judging by your comment you most likely associate WCF with various SOA technologies like XML and SOAP. WCF is in fact a communication framework designed to be extended for different protocols. It is true that most of the out-of-the-box extensions are related to SOA (a consequence of the time when WCF was released) but extensions can be written/exist for REST (HTTP / JSON), protocol buffers, gRPC, or even a custom protocol. – Ethan Cabiac Jul 17 '17 at 20:20
This is one technique of calling or consuming rest webservice in asp.net c#
var client = new RestClient("url");
var request = new RestRequest(Method.POST);
request.AddHeader("content-type", "application/json");
request.AddParameter("application/x-www-form-urlencoded",
"type=password& user_id=test@gmail.com",ParameterType.RequestBody);
IRestResponse response = client.Execute(request);

- 29,542
- 12
- 100
- 122

- 21
- 2
I just released a REST client here today. You can download the Git repo to see the samples. https://bitbucket.org/MelbourneDeveloper/restclient-.net
- Open Source. (MIT License)
- Markup language agnostic. (Supports JSON, SOAP and other markup languages)
- Use strong types with REST.
- Supports Android, iOS, Windows 10, Windows 10 Phone, Silverlight, .NET, .NET Core.
- Incredibly simple.
- Async friendly (uses async, await keywords).
When is WCF(using the WebChannelFactory) more preferable to HttpClient?
That is a very loaded question. WCF is a very large collection of technologies that allow you to communicate with a number of different protocols, authentication methods, and so on. It is very configurable, but REST is simple and supported by nearly all technologies available. If you write a REST service, chances are that nearly any app could consume it. Really, the question is about who your target audience is.

- 6,770
- 5
- 51
- 103