Wcf VS ASP.NET Web API

WCF vs ASP.NET Web API

The new ASP.NET Web API is a continuation of the previous WCF Web API project (although some of the concepts have changed).

WCF was originally created to enable SOAP-based services. For simpler RESTful or RPCish services (think clients like jQuery) ASP.NET Web API should be good choice.

Difference between wcf restful services and WEB API

Web Service

  • It is based on SOAP and returns data in XML format.
  • It supports only the HTTP protocol.
  • It is not open source but can be consumed by any client that understands XML.
  • It can be hosted only on IIS.



WCF

  • It is also based on SOAP and returns data in XML format.
  • It is the evolution of web services (ASMX) and support various protocols like TCP, HTTP, HTTPS, Named Pipes, MSMQ.
  • The main issue with WCF is its tedious and extensive configuration.
  • It is not open source but can be consumed by any client that understands XML.
  • It can be hosted with in the application or on IIS or using window service.



WCF REST

  • To use WCF as a WCF REST service you have to enable webHttpBindings.
  • It supports HTTP GET and POST verbs by [WebGet] and [WebInvoke] attributes respectively.
  • To enable other HTTP verbs you have to do some configuration in IIS to accept request of that particular verb on .svc files.
  • Passing data through parameters using a WebGet needs configuration. The UriTemplate must be specified.
  • It supports XML, JSON and ATOM data format.



Web API

  • This is the new framework for building HTTP services the easy and simple way.
  • Web API is open source an ideal platform for building RESTful services using the .NET Framework.
  • Unlike a WCF REST service, it use the full features of HTTP (like URIs, request/response headers, caching, versioning, various content formats).
  • It also supports the MVC features such as routing, controllers, action results, filter, model binders, IOC container or dependency injection, unit testing that makes it more simple and robust.
  • It can be hosted within the application or on IIS.
  • It is a light weight architecture and good for devices which have limited bandwidth like smart phones.
  • Responses are formatted by Web API’s MediaTypeFormatter into JSON, XML or whatever format you want to add as a MediaTypeFormatter.



Choosing between WCF or Web API

  • Choose WCF when you want to create a service that should support special scenarios such as one way messaging, message queues, duplex communication etc.
  • Choose WCF when you want to create a service that can use fast transport channels when available, such as TCP, Named Pipes, or maybe even UDP (in WCF 4.5), and you also want to support HTTP when all other transport channels are unavailable.
  • Choose Web API when you want to create a resource-oriented services over HTTP that can use the full features of HTTP (like URIs, request/response headers, caching, versioning, various content formats).
  • Choose Web API when you want to expose your service to a broad range of clients including browsers, mobiles, iPhone and tablets.

For more details you can refer to http://www.c-sharpcorner.com/UploadFile/8a67c0/who-is-winner-web-api-or-wcf/.

What's the difference between WCF Web API and ASP.NET Web API

Ive done a little more reading around this and found a few pages by MS people on this:

http://wcf.codeplex.com/wikipage?title=How%20to%20Migrate%20from%20WCF%20Web%20API%20to%20ASP.NET%20Web%20API :

The WCF Web API abstractions map to ASP.NET Web API roughly as follows

WCF Web API -> ASP.NET Web API

  • Service -> Web API controller
  • Operation -> Action
  • Service contract -> Not applicable
  • Endpoint -> Not applicable
  • URI templates -> ASP.NET Routing
  • Message handlers -> Same
  • Formatters -> Same
  • Operation handlers -> Filters, model binders

and http://wcf.codeplex.com/discussions/319671

The integrated stack supports the following features:

  • Modern HTTP programming model
  • Full support for ASP.NET Routing
  • Content negotiation and custom formatters
  • Model binding and validation
  • Filters
  • Query composition
  • Easy to unit test
  • Improved Inversion of Control (IoC) via DependencyResolver
  • Code-based configuration
  • Self-host

Difference between WCF, Web API, WCF REST and Web Service?

The .Net framework has a number of technologies that allow you to create HTTP services such as Web Service, WCF and now Web API. There are a lot of articles over the internet which may describe to whom you should use.

Web Service

  • It is based on SOAP and return data in XML form.
  • It support only HTTP protocol.
  • It is not open source but can be consumed by any client that understands xml.
  • It can be hosted only on IIS.

WCF

  • It is also based on SOAP and return data in XML form.
  • It is the evolution of the web service(ASMX) and support various protocols like TCP, HTTP, HTTPS, Named Pipes, MSMQ.
  • The main issue with WCF is, its tedious and extensive configuration.
  • It is not open source but can be consumed by any client that understands xml.
  • It can be hosted with in the applicaion or on IIS or using window service.

WCF Rest

  • To use WCF as WCF Rest service you have to enable webHttpBindings.
  • It support HTTP GET and POST verbs by [WebGet] and [WebInvoke] attributes respectively.
  • To enable other HTTP verbs you have to do some configuration in IIS to accept request of that particular verb on .svc files
  • Passing data through parameters using a WebGet needs configuration. The UriTemplate must be specified.
  • It support XML, JSON and ATOM data format.

Web API

  • This is the new framework for building HTTP services with easy and simple way.
  • Web API is open source an ideal platform for building REST-ful services over the .NET Framework.
  • Unlike WCF Rest service, it use the full feature of HTTP (like URIs, request/response headers, caching, versioning, various content formats)
  • It also supports the MVC features such as routing, controllers, action results, filter, model binders, IOC container or dependency injection, unit testing that makes it more simple and robust.
  • It can be hosted with in the application or on IIS.
  • It is light weight architecture and good for devices which have limited bandwidth like smart phones.
  • Responses are formatted by Web API’s MediaTypeFormatter into JSON, XML or whatever format you want to add as a MediaTypeFormatter.

To whom choose between WCF or WEB API

  • Choose WCF when you want to create a service that should support special scenarios such as one way messaging, message queues, duplex communication etc.
  • Choose WCF when you want to create a service that can use fast transport channels when available, such as TCP, Named Pipes, or maybe even UDP (in WCF 4.5), and you also want to support HTTP when all other transport channels are unavailable.
  • Choose Web API when you want to create a resource-oriented services over HTTP that can use the full features of HTTP (like URIs, request/response headers, caching, versioning, various content formats).
  • Choose Web API when you want to expose your service to a broad range of clients including browsers, mobiles, iphone and tablets.

Reference: http://www.dotnettricks.com

Author : Shailendra Chauhan

WCF Service vs ASP.NET Web Api

From http://mattmilner.com/Milner/Blog/post/2012/02/28/WebAPI-or-WCF.aspx, a great post on this issue: "WCF remains the framework for building services where you care about transport flexibility. Web API is the framework for building services where you care about HTTP."

WCF and ASP.NET Web API: Benefits of both?

I answered a couple of related questions:

  • What is the future of ASP.NET MVC framework after releasing the asp.net Web API

  • Should it be a WebAPI or asmx

As an additional resource, I would like to recommend you to read:

http://www.codeproject.com/Articles/341414/WCF-or-ASP-NET-Web-APIs-My-two-cents-on-the-subjec

If you want to learn more about REST, check this Martin Fowler article

Summaring up:

As far as I know, both technologies are being developed by the same team in Microsoft, WCF won't be discontinued, it will still be an option (for example, if you want to increase the performance of your services, you could expose them through TCP or Named Pipes). The future is clearly Web API

  • WCF is built to work with SOAP

  • Web API is built to work with HTTP

In order to take the correct choice:

  • If your intention is to create services that support special scenarios – one way messaging, message queues, duplex communication etc, then you’re better of picking WCF
  • If you want to create services that can use fast transport channels when available, such as TCP, Named Pipes, or maybe even UDP (in WCF 4.5), and you also want to support HTTP when all other transports are unavailable, then you’re better off with WCF and using both SOAP-based bindings and the WebHttp binding.
  • If you want to create resource-oriented services over HTTP that can use the full features of HTTP – define cache control for browsers, versioning and concurrency using ETags, pass various content types such as images, documents, HTML pages etc., use URI templates to include Task URIs in your responses, then the new Web APIs are the best choice for you.
  • If you want to create a multi-target service that can be used as both resource-oriented service over HTTP and as RPC-style SOAP service over TCP – talk to me first, so I’ll give you some pointers.

Difference summary WCF and Web API

this list is by no means exhaustive.

Things WCF does that you cannot do (with ease) using Web API.

  1. Supports SOAP based XML format.
  2. Supports strongly typed data contracts.
  3. Supports a single point of metadata information exchange using WSDL etc.
  4. Supports varied bindings like TCP, Named Pipes, MSMQ, even UDP etc.
  5. Supports varied hosting options like console apps, WAS, IIS, Windows Services.
  6. Supports one way messaging, duplex, message queues out of the box.
  7. Supports multiple authentication schemes like Windows, Forms, Certificates etc.

Things Web API does that you cannot do (with ease) using WCF.

  1. Supports the full features of HTTP. (Uri based access, Http Requests/Response, Http Caching etc.) To do this in WCF you need to additional work to configure it as REST service etc.
  2. Is Lightweight with minimal configuration.
  3. Supports the Routing, Controller/Action MVC paradigm, Model Binding etc.

Basically Web API is an easy way to do RESTful services over Http without knowing much about Web services.

To do the same in WCF, you need to do additional work in terms of httpBindings, UriTemplates, Verbs etc. And that means, understanding WCF first. And then using WCF to implement a RESTFul service over http, which is what Web Api provides out of the box.



Related Topics



Leave a reply



Submit