DCSIMG
WCF or ASP.NET Web APIs? My two cents on the subject - Ido Flatow's Blog Veni Vidi Scripsi

Ido Flatow's Blog

Veni Vidi Scripsi

News

Have you heard me speak?
Powered
<style type='text/css' media='screen' id='sm_css'> #smix {overflow: visible;height: auto;border-radius: 10px;max-width: 250px;background-color: #323232;text-align: left;font-size: 12px;line-height: 16px;font-family:'Lucida Sans Unicode','Lucida Grande',Verdana,Arial,Helvetica,sans-serif;-webkit-border-radius: 10px;-moz-border-radius: 10px;border-radius: 10px;} #smix a {color: #0056CC;text-decoration: none;} #smix .sm_head {color: #fff; line-height: 1em;font-size: 1.4em;padding: 10px;color: #fff;} #smix .sm_lanyard_wrapper {background-color: #fff;;clear: both;width: 97%;margin: 0 auto;margin-bottom: 0px;} #smix .sm_lanyard_content {padding: 7px;}#smix button.sm_rec, #smix a.sm_rec, #smix input[type=submit].sm_rec { padding: 6px 10px; -webkit-border-radius: 2px 2px;-moz-border-radius: 2px; border-radius: 2px; border: solid 1px rgb(153, 153, 153); background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(rgb(255, 255, 255)), to(rgb(221, 221, 221))); color: #333; text-decoration: none; cursor: pointer; display: inline-block; text-align: center; text-shadow: 0px 1px 1px rgba(255,255,255,1); line-height: 1; }#smix .sm_rec:hover { background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(rgb(248, 248, 248)), to(rgb(221, 221, 221))); }#smix .sm_rec:active { background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(rgb(204, 204, 204)), to(rgb(221, 221, 221))); }#smix .sm_rec.medium { padding: 3px 7px; font-size: 13px; }#smix .sm_rec span.icon.thumbs_up {background-position: 0px 36px;vertical-align: text-top;display: inline-block;margin-right: 4px;height: 18px;width: 16px;background-image: url(http://speakermix.com/images/new/thumbsold.png);}#smix .sm_rec:hover span.icon.thumbs_up {background-position: 0px 18px;} #smix .sm_events {padding:2px 0px 4px 0px;} #smix .sm_section {font-size: 10px; border-bottom: 1px solid silver; margin-bottom: 6px;} #smix .sm_subline {font-size:120%;margin-top:4px;font-weight:bold} #smix .powered {text-align: right} #smix .powered img {margin: 7px} </style>
Sela Technology Center

Advertisement

WCF or ASP.NET Web APIs? My two cents on the subject

A couple of weeks ago (around Feb. 16) the WCF WebAPIs - a framework for building RESTful/Hypermedia/HTTP services, which was in development over the past 1.5 years as a side-project on CodePlex, has been formally integrated into ASP.NET and its name changed to the ASP.NET Web API.

These past two weeks, there has been a lot of questions among WCF developers: What does it mean that the Web APIs are no longer a part of WCF – is WCF dead? Has SOAP gone bankrupted? is HTTP the new way to go for interoperability?

To get a better understanding of what happened and what is the way to go, we need to answer a couple of questions:

1. What is the purpose of the WebAPIs?

2. Why do we need REST HTTP services? What’s wrong with SOAP-over-HTTP?

3. Why did the WebAPIs move from WCF to ASP.NET MVC?

4. Is there still a use for WCF? When should I choose Web APIs over WCF?

What is the purpose of the WebAPIs?

When WCF was conceived back in its Indigo and .NET 3 days, the main goal was to support SOAP + WS-* over a wide variety of transports. However, over time it became clear that although SOAP is wide spread and supported on many platforms, it is not the only way to go when creating services. There is also a need to also support non-SOAP services, especially over HTTP, where you can harness the power of the HTTP protocol to create HTTP services: services that are activated by simple GET requests, or by passing plain XML over POST, and respond with non-SOAP content such as plain XML, a JSON string, or any other content that can be used by the consumer. Support for non-SOAP services was very much needed in WCF back then, mostly because some clients, such as web browsers, were not that suitable to handle SOAP messages (plenty of XML parsing and DOM manipulation).

So in WCF 3.5 we got the WebHttpBinding – a new binding that helped us create this kind of non-SOAP service over HTTP, better known as a RESTful service.

The WebHttpBinding was not enough, and after WCF 3.5 was released, a new set of tools was created – the WCF REST Starter Kit. The REST starter kit was an attempt to enrich the support of WCF 3.5 for HTTP services – add better client-side support for .NET apps, extend the server side support for other content types, enable response and request caching, inspection of messages and so forth. Unfortunately, this great toolkit was never officially released and ended its product cycle as “Preview 2”, although it’s still being used today in some of Microsoft’s products that are built with .NET 3.5.

Although not released, some of the service-side features of the REST starter kit were integrated into WCF 4 – we didn’t get any of the client-side libraries, but we did get most of the service-side features (excluding the new inspectors). Some were well-integrated into WCF while others required the use of ASP.NET (by turning on the ASP.NET compatibility mode).

So with WCF 4 we had some support for “Web” HTTP services, but it wasn’t that perfect – to get some of the features you needed IIS hosting and ASP.NET, not all types of requests were supported easily (ever tried posting HTML form data to a WCF HTTP service?), the overuse of CLR attributes to define the POST/GET/PUT/DELETE was tedious, not to mention the configuration required to create this type of services with all of the endpoint behavior. And even after all of that we didn’t actually get full control over the HTTP messages.

That was the main goal of the Web APIs, known back then as the WCF Web APIs: to stop looking at HTTP through the eyes of WCF - as just a transport protocol to pass requests. Rather, it allows us to look at it as the real application-level protocol it is – a rich, interoperable, resource-oriented protocol. The purpose of the Web APIs was to properly use URIs, HTTP headers, and body to create HTTP services for the web, and for everyone else that wished to embrace HTTP as its protocol and lifelong friend.

Why do we need REST HTTP services? What’s wrong with SOAP-over-HTTP?

The world of SOAP and the world of HTTP services are very different. SOAP allows us to place all the knowledge required by our service in the message itself, disregarding its transport protocol, whether it is TCP, HTTP, UDP, PGM, Named Pipes… But unlike TCP, UDP and the other level 4-5 protocols, HTTP is an application-level protocol, and as such it offers a wide variety of features:

  • It supports verbs that define the action - query information using GET, place new information and update existing using POST or PUT, remove information using DELETE etc.
  • It contains message headers that are very meaningful and descriptive - headers that suggest the content type of the message’s body, headers that explain how to cache information, how to secure it etc.
  • It contains a body that can be used for any type of content, not just XML content as SOAP enforces (and if you want something else – encode it to base64 strings and place it in the SOAP’s XML content). The body of HTTP messages can be anything you want – HTML, plain XML, JSON, binary files (images, videos, documents…) …
  • It uses URIs for identifying both information paths (resources) and actions – the URI templates initiative is catching on and is rapidly becoming the standard way of representing requests for resources and hypermedia URIs.

The use of HTTP has evolved over the years. Application-level protocol architectural styles such as REST Hypermedia APIs have emerged on top of HTTP. These, in turn, harness the power of HTTP to create resource-oriented services, and better define the stateless interaction between clients and services.

The Web APIs therefore were intended to allow all of these approaches – you can use it to create HTTP services that only use the standard HTTP concepts (URIs and verbs), and to to create services that use more advanced HTTP features – request/response headers, hypermedia concepts etc.

So HTTP is a lot more than a transport protocol. It is an application-level protocol, and the fact is that although many platforms know how to use SOAP, many more platforms know how to use HTTP! among the HTTP supporting platforms which do not support SOAP that well are the browsers – probably the most important platforms for web developers (and users). And if you don’t believe me that REST and hypermedia are useful, maybe Martin Fowler can convince you better than me.

This, of course, does not mean that SOAP is redundant – SOAP is still useful for building messages when you don’t have an alternative application-level protocol at your disposal, or when you want to use SOAP across the board while considering HTTP as no more than another way to pass messages (for example, use HTTP because it can cross firewalls more easily than TCP).

Why did the WebAPIs move from WCF to ASP.NET MVC?

Back to the story of WCF and the WCF Web APIs (we are still before the merger). Another goal of the WCF Web APIs was to incorporate known concepts that would help developers to overcome some of the drawbacks they faced with WCF, such as huge configurations, overuse of attributes, and the WCF infrastructure that did not support testing well. Thus the Web APIs used IoC, enabled convention-over-configuration, and tried to offer simpler configuration environment.

The problem was that at that point in time there were several approaches for constructing HTTP services:

1. WCF with the WebHttp binding and REST support.

2. The new WCF Web APIs, soon to be ASP.NET Web APIs.

3. A not-so-new framework, ASP.NET MVC, which took a break from being HTML-oriented (getting requests from HTML pages and returning HTML/JSON) to being Resource-oriented – people started realizing that they can consider controllers as services and use the MVC infrastructure to define the control requests, responses, and better control the HTTP message.

4. Open source frameworks such as OpenRasta and ServiceStack.

In addition to that, as time passed, the WCF Web APIs had a lot of trouble adapting WCF to the “native” HTTP world. As WCF was primarily designed for SOAP-based XML messages, and the “open-heart” surgery that was required to make the Web API work as part of WCF was a bit too much (or so I understand from people who were involved in creating the Web APIs). On the other hand, the ASP.NET MVC infrastructure with its elegant handling of HTTP requests and responses, and its support of easy-to-create controllers seemed like the proper way to go for creating this new type of services.

So the fact was we had too many options and therefore too much confusion. What were we to do? We merge teams! (Kind of reminds us of the time of LINQ-to-SQL and Entity Framework, WCF and Ado.Net Data Services and other such examples). So the WCF team and the ASP.NET team joined forces and created a new framework focused on the world of REST/Hypermedia/HTTP services for the web world and thus came out the ASP.NET Web APIs.

I’m still not so sure about the choice of names, as the new Web APIs can also work outside of ASP.NET with the use of WCF, but I guess that the name “WCF ASP.NET Web API” was a bit long. Maybe “WASP Web API”? “WAWAPI” (Wcf Aspnet Web API)? Or maybe simply call it “Hypermedia Web API”?

So this merger is intended to reduce confusion, not induce it. I guess that if it was explained at that time, it might have caused less confusion over time (see the Silverlight is dead slip of PDC 2010). Does Microsoft need a new DevDiv PR team?

Is there still use for WCF? when should I choose Web APIs over WCF?

Recall my points from before - HTTP is a lot more than a transport protocol; use SOAP across the board and consider HTTP as no more than another way to pass messages.

  • 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.

I hope this helped you removing some of the confusion over this topic.

Comments

Paulo said:

"to stop looking at HTTP through the eyes of WCF - as just a transport protocol to pass requests. Rather, it allows us to look at it as the real application-level protocol"

Wow, what a great insight, thank you. Now I am starting to understand all this changes.

As for the "multi-target service" you mentioned on the last sentence, can you elaborate more on that? For example, will it be possible to use a hybrid approach, like hosting the Web API outside ASP.NET?

# March 6, 2012 3:49 AM

Ido Flatow said:

Hi Paulo,

the Web APIs can be hosted outside of ASP.NET, by using WCF as the hosting environment.

Check out this blog post that shows how to do it:

devlicio.us/.../zero-to-self-hosting-aspnet-webapi-in-a-few-short-steps.aspx

# March 6, 2012 3:52 PM

DotNetKicks.com said:

You've been kicked (a good thing) - Trackback from DotNetKicks.com

# March 7, 2012 3:14 PM

Yevhen said:

"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."

So when can we expect a blog post on the matter? ;)

# March 8, 2012 12:34 AM

The Morning Brew - Chris Alcock » The Morning Brew #1060 said:

Pingback from  The Morning Brew - Chris Alcock  &raquo; The Morning Brew #1060

# March 8, 2012 10:41 AM

Ali Hmer said:

What a comprehensive explanation. You should consider writing a book about WCF and Web API.

# March 8, 2012 9:29 PM

Interesting Finds: March 8, 2012 « Hank Wallace said:

Pingback from  Interesting Finds: March 8, 2012 &laquo; Hank Wallace

# March 8, 2012 9:35 PM

Distributed Weekly 145 — Scott Banwart's Blog said:

Pingback from  Distributed Weekly 145  &mdash;  Scott Banwart&#039;s Blog

# March 9, 2012 4:43 PM

Ido Flatow said:

Ali,

Thanks for the compliments. I've actually written a book about WCF 4 before for Microsoft, as part of the Microsoft's WCF 4 course (10263A). I'm still considering whether I will have time for another book if an opportunity arises.

blogs.microsoft.co.il/.../reminiscing-the-creation-of-the-wcf-4-moc.aspx

# March 9, 2012 7:10 PM

“Truly understanding ASP.NET Web API” sau h????i??ul acronimelor | Tudor Turcu – blog said:

Pingback from  &#8220;Truly understanding ASP.NET Web API&#8221; sau h????i??ul acronimelor | Tudor Turcu &#8211; blog

# March 9, 2012 10:28 PM

Is there an equivalent to ASP.NET Web API in the Rails world? | DIGG LINK said:

Pingback from  Is there an equivalent to ASP.NET Web API in the Rails world? | DIGG LINK

# March 24, 2012 12:06 AM

What is RESful service and designning RESTful service using ASP.NET | Broken Code said:

Pingback from  What is RESful service and designning RESTful service using ASP.NET | Broken Code

# June 28, 2012 8:21 PM

Rajesh said:

Hi,

If you are targeting a web portal that can be accessed via desktop and mobile browsers, and want to leverage MVC 4 for UI and Web API for services (hosted on IIS) in a RESTful implementation ==> what do you think can be the big challenges here? I mean challenges if we are not used traditional web forms with wCF services model.

I want to emphasize that this web portal using MVC 4 + web API is intended to be used in production environmnet and accessed my many users. Will appreciate any pointers and detail explaination.

Thanks,

Rajesh

rajesh_gupta1@yahoo.com

# July 2, 2012 6:28 AM

Colin E. said:

An excellent blog post. Very informative and useful. Have 5-stars ;-)

# July 16, 2012 1:21 PM

Chase said:

Just the type of insight we need to fire up the deatbe.

# July 21, 2012 6:17 PM

Whiteman said:

Everything is very open with a clear explanation of the challenges.

It was really informative. Your site is extremely helpful.

Thank you for sharing!

# July 22, 2012 10:12 PM

Albright said:

WOW just what I was searching for. Came here by searching for men

# August 2, 2012 11:55 PM

Yuri Livshitz said:

I really like the fact that you were able to capture the evolution of REST and its adaptation by Web API in one small article. Great work!

# August 22, 2012 10:58 PM

Figueroa said:

I think the admin of this web page is truly working hard in support of his

site, as here every data is quality based information.

# September 13, 2012 11:52 PM

icon design said:

 In it something is also idea good, I support.

P.S. Please review our <a href="www.softlocate.com/p022841_Perfect_Icon.html">icons for Windows</a>  and windows12icons.

# September 14, 2012 11:53 AM

icon design said:

 It is remarkable, rather amusing message

P.S. Please review our <a href="onlineinfodirectory.com/.../ready-made-professionaly-crafted-icons-for-web-design-t37960.html">icons for Windows</a>  and windows12icons.

# September 14, 2012 1:35 PM

icon design said:

 I can suggest to visit to you a site on which there are mazny articles on this question.

P.S. Please review our <a href="www.5starfiles.com/.../Large_Home_Icons_purchase.php">icons for Windows</a>  and windows12icons.

# September 15, 2012 7:43 AM

icon design said:

 The charming answer

P.S. Please review our <a href="sport-icons.updatestar.com/fr">icons for Windows</a>  and windows12icons.

# September 15, 2012 10:29 AM

icon design said:

 Should you tell.

P.S. Please review our <a href="www.dlmass.com/.../">icons for Windows</a>  and windows12icons.

# September 15, 2012 11:39 AM

icon design said:

 I think, that you commit an ereor. Write to me in PM, we will communicate.

P.S. Please review our <a href="www.5starfiles.com/.../Money_Toolbar_Icons_publisher.php">icons for Windows</a>  and windows12icons.

# September 15, 2012 12:46 PM

icon design said:

 I consider, that you are mistaken. I suggest it to discuss. Write to me in PM, we will communicate.

P.S. Please review our <a href="telecharger-gratuit.com/.../iconxp-3.html">icons for Windows</a>  and windows12icons.

# September 15, 2012 1:52 PM

Shanahan said:

I know this web site provides quality dependent articles or reviews

and other material, is there any other web page which offers

these data in quality?

# September 27, 2012 3:00 PM

Offshore Software Development Company said:

Exactly what I needed to know about WebApi and couldn't find on msdn or asp.net or any of Microsoft’s official webapi content.

# October 1, 2012 2:57 PM

Thomason said:

Thus Texas drivers can sue each other for out of pocket medical expenses and also

secondary damages like emotional distress. Others will take your complete application, including all your personal information such as a phone

number, address, and the specifics of your driving history, where you park your car, and other

important factors that go into determining your final rate.

If you have been your seventeen-year-old year-old

male surviving in inborn Manchester, consequently you need to beginning conserving : your answers

claim that you may just give above anybody the european union

for ones online auto insurance.

# October 26, 2012 11:53 AM

Sleeper said:

Excellent excellent post. But if Hypermedia API is the reason behind the drive for WebAPI, then I must ask, why do we still have Controller and ApiController class? Human readable webpage is merely another supported MIME type media of the Hypermedia API isn't it?

To separate them is like saying "WebApi handles all mime type except for text/html for which you go --> over there". Can WebAPI handle text/html, ok maybe it can handle, but does it (or will it) retain and assimilate the feature set of ASP.NET MVC?

Otherwise, if all it does it xml/json, WCF is perfectly capable of handling it with some custom behaviors, [WebInvoke] Attributes with appropriate verbs??

Again, thx for the post. Awesome read.

# December 11, 2012 1:10 AM

Moen said:

In all instances they say their mental attitude as well as their outlook

on life has totally changed. 4 - Green tea extract - regular consumption can promote weight-loss by adjusting resting energy and increasing the use of

energy. For many, the diet is easy to follow simply

because they don.

# January 24, 2013 9:15 PM

Blanton said:

Many people have experienced success with many side effects include difficulty with getting a free wrinkle remover and Hyperhidrosis.

When you get your mouth frozen for dental work all the time, general

hyperhidrosis. Others suggest even more difficult- it hard to get some good breathing to slow down your forehead all the options

should be tagged for single use only by family members.

Another effective way to regulate body temperature. You can prepare this device back home with

the nervous system.

# January 26, 2013 7:43 PM

Soci blog » Blog Archive » WCF REST t??mogat??s vagy ASP.NET WepAPI? said:

Pingback from  Soci blog  &raquo; Blog Archive   &raquo; WCF REST t??mogat??s vagy ASP.NET WepAPI?

# February 1, 2013 8:21 AM

Soczó Zsolt Szakmai blogja said:

Jó kis összefoglaló a témáról, miért kellett ASP.NET-be újra megcsinálni a dolgokat.

# February 1, 2013 8:39 AM

Brownlee said:

In short, when it comes to sugars think minimal and natural.

For more information, or to purchase Wii Fit or Wii Fit Plus, visit.

You might wonder why you should talk to anyone about getting

a *** augmentation.

# March 1, 2013 10:21 AM

Sayre said:

Hi there, I enjoy reading through your post.

I wanted to write a little comment to support you.

# March 10, 2013 3:53 PM

Larose said:

What's up, all the time i used to check blog posts here early in the daylight, because i enjoy to learn more and more.

# March 14, 2013 3:33 AM

Craig Darling said:

Awesome post.  We've been grappling with REST / non-REST and how that fits into the world of WCF, etc..  Thanks for the clear guidance!

# March 27, 2013 9:58 AM

Pollack said:

Please consult your physician before starting any alternative modalities.

In short, there is no significant evidence that silver harms the liver or

the nervous system. Less is more when it comes to these products because too much can severally dry out the skin, making acne even worse.

# March 27, 2013 10:54 AM

Ethridge said:

Thanks for sharing your thoughts. I really appreciate your efforts and I am waiting

for your next write ups thank you once again.

# April 1, 2013 8:21 PM

Ingebynenty said:

Hello. And Bye.

# April 10, 2013 9:23 PM

XRumerTest said:

Hello. And Bye.

# April 10, 2013 11:22 PM

elipleNub said:

Nike Manumitted TR Trim 3 prominent features is to from the trendy plot: Nike Let off 5 soles improved bending Gouge; modern tractor imitate making training more focused when; lighter ballast, the permeability is stronger, and more in fashion shoe designs not just order shoes [url=hear4you.com/catalogues.cfm]cheap nike air max 1[/url]

more serene wearing, barefoot training caress, but also more fashionable appearance.

Nike Manumitted TR Fitting 3 provides supreme lateral stability, you can have the legs in the untenable during training. Eager vamp superiority breathable webbing, drop suds's one of a kind delineate can be [url=hear4you.com/catalogues.cfm]air max 1[/url]

seen from stem to stern it. Lightweight, demanding, pinched soap up facts familiar at hand very only one seams, more amenable, support is stronger. Lack more support, factor of a training vex, lather make inaccessible in more parts of the need championing agreeableness, foam loose. Say twice tongue moisture wicking fake materials, vapid on your feet, hands keep feet tiring and comfortable. Phylite [url=markwarren.org.uk/property-waet.cfm]air max 90[/url]

midsole offers lightweight shock unceasing, superior durability and stable outsole can do to greatly turn the total weight of the shoe. Qianzhang pods on the outsole and heel-shaped Green rubber enhances the shoe multi-directional traction on extraordinary surfaces.

# April 22, 2013 5:18 AM

More about WCF or Web API ?? CodeEase.com said:

Pingback from  More about WCF or Web API ?? CodeEase.com

# April 28, 2013 12:27 AM

vbpweqbohlw@gmail.com said:

What's up, I also desire to share my view at this time, when i don抰 know even about a effortless thing related to PHP, I always go to explore that from web.

# May 15, 2013 7:54 PM
Leave a Comment

(required) 

(required) 

(optional)

(required) 


Enter the numbers above: