What are my options to consume a RESTful service using the .Net framework? When is WCF(using the WebChannelFactory) more preferable to HttpClient?
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Generic Generics in Managed C++
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
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.
There are few different ways of consuming REST services in .NET:
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.
The hammock project makes it very easy to consume RESTful services, you can use it to easily create the required http requests you need:
https://github.com/danielcrenna/hammock
I just released a REST client here today. You can download the Git repo to see the samples. https://bitbucket.org/MelbourneDeveloper/restclient-.net
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.
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.
This is one technique of calling or consuming rest webservice in asp.net c#