There are currently other significant differences between WebApi and WCF data services that no one ever mentions. I want MS to come out with a good article comparing them.
I watched OData for a while, as well as WebApi. I have always found several important differences.
First, I'm not sure if your boss means that "MS supports WebApi," because it means they don't support OData ?? IMO, they support both options, and there is currently some minimal overlap. Windows Azure Data Market provides its data using OData, Azure Table Storage uses OData, SharePoint 2010 allows OData Queries over it Data and other products from MS also support it, such as Excel PowerPivot. This is a very powerful query structure when it comes to relational data. And since it is RESTful, any language, infrastructure, device, etc. They can integrate with it.
Here's what I like about OData + WCF Data Services:
The OData + WCF data service has finally allowed client applications to be more "expressive" when requesting data over the Internet. Previously, we always had to use ASMX or WCF to create hard web APIs that become invulnerable and require constant changes whenever the user interface wants something a little different. The client application can specify only parameters to dictate which criteria to return. Or do as I did, and “Serialize” LINQ expressions and pass them as parameters and rewet them in Expressions<Func<T,bool>> on the server. This is decent. The work is done, but I want to use LINQ on the client and translate it over the Internet using REST, which is exactly what OData allows, and I don’t want to use my own “hack” solution.
He wanted to expose "TRANSACT SQL" without having to create a DB connection string. Just specify Url and whoala! Start request. Of course, WebApi services and WCF services support authentication / authorization, so you can control access, add additional Where instructions based on roles or other data configuration. I would rather do this in my Api web layer than in SQL (e.g. as buildings or saved proxies). And now that applications can create their own queries, you’ll see Ad-Hoc and BI Reporting tools that start using OData and allow users to define their own results. Without relying on static reports, where they have minimal control.
When developing in Silverlight, Windows 8 Metro or ASP.NET (MVC, WebForms, etc.) you can simply add the "Service link" in Visual Studio to the WCF data service and quickly start using LINQ to query AND data you get "Context data "on the client, which means that it tracks changes and allows you to" send "your changes in physical order back to the Server. This is very similar to RIA Services for Silverlight. I would use WCF data services instead of RIA Services, but at that time it did not support DataAnnotations or Actions, but now it happens :) WCF data services have one more advantage over RIA services, which allows you to perform "Forecasts" from the Client. This can help in performance if I don't want to return all properties from an object. The presence of a "Data Context" on the client is great when working with Line-Of-Business applications.
In this way, WCF data services are great if you have data with relationships, especially if you are using SQL Server and Entity Framework. You can quickly set Queryable Data + Actions (calls to invoke operations, that is, workflows, background processes) on REST with very little code. The WCF data service has just been updated. New version released. Check out all the new features.
The downside of WCF data services is the “control” you lose over the HTTP stack. I found the biggest flaw in the IQueryable<T> methods that return collections. Unlike RIA and WebApi services, you do NOT have full access to develop logic in the IQueryable method. In RIA and WebApi services, you can write whatever code you want as long as you return IQueryable<T> . In WCF data services, you ONLY gain access to the Where append using the Expression<Func<T,bool>> interceptor methods. I found this disappointing. Our current application uses RIA services, and I believe that we really need the ability to control IQueryable logic. Hope I'm wrong about that and I just missed something.
In addition, WCF Data Services does not yet fully support all LINQ statements. It still supports more than WebApi.
How about WebApi ???
- I like the control over the HTTP Request / Response
- Easy to follow (using MVC templates). I am sure more tools will appear.
At the moment (as far as I know) there is no support for the "Data Context" client (for example, Silverlight, ASP.NET server-side code, etc.), since WebApi is not related to data about data objects, such as WCF data Services / OData. It can expose collections of model objects using IQueryable / IEnumerable, but there is no primary key / foreign key "Navigation Properties" (that is customer.Invoices) to use after the objects are loaded on the Client, because there is no "Data Context" which downloads them asynchronously (or in a single call using $ expand) and manages the changes. You do not have the code-generated “view” of your entity data model on the client, for example, in RIA services or WCF data services. I am not saying that you do not have / do not have models in the client that represent your data, but you manually fill in the data and manage which “invoices” should be set with each “client” after receiving the web. This may seem complicated, especially with all Async stuff. You do not know which calls will return in the first place. This may be difficult to explain here, but just read the “Data Context” material in RIA or WCF Data Services . Therefore, dealing with a line of business applications, for me this is a serious problem. This is mainly based on performance and maintainability. You can smooth applications without a data context. It just makes things easier, especially with Silverlight, WPF, and now with Windows 8 Metro. Having relational entities loaded into memory asynchronously and having dual binding is really nice to have.
Having said that, does this mean that someday WebApi will be able to support the "Data Context" on the client? I think it's possible. In addition, with the help of additional tools, Visual Studio Project can generate all your CRUD methods based on a database schema (or Entity Framework).
Also, I know that I mention .NET for the .NET Framework when it comes to working with WCF or WebApi data services, but I know very well that HTML / JS is also a major player. I just mentioned the benefits I found when working with the Silverlight user interface, or with ASP.NET server-side code, etc. I believe that with the advent of “IndexedDB” in HTML5 / JavaScript having a “Data Context” and in addition, the LINQ platform in JavaScript has become available, which has simplified the ability to query OData Services with JavaScript (you can use DataJS today with OData). Also, using KnockoutJS to support MVVM and Binding in HTML / JS, make it easy :)
I am currently studying which platform to use. I would be happy to take advantage of this, but I tend to lean towards OData, based on the fact that my next application is primarily about Google Analytics (read-only) and I want a rich expressive RESTful Api. I believe OData + WCF Data Services gives me this because WebApi only supports $ take, $ skip, $ filter, $ orderby over Collections. It does NOT support forecasts, includes ($ expand), etc. I don't have many “Updates / Deletes / Attachments”, and our data is pretty relational.
I hope that others join the discussion and express their thoughts. I am still deciding and would like to hear other opinions. I really think both are great. I wonder if you need to choose, why not use both options if necessary. From the Client, all this concerns the creation of REST calls in any case. Just a thought :)