WCF Data Services (OData) Vs ASP.NET Web API

I am developing a distributed application that will consist of RESTful services and many clients (Silverlight, iOS, Windows Phone 7, etc.). I am now determining which technology I should use to implement my services, WCF Data Services (OData), or the new ASP.NET Web API that comes with ASP.NET MVC 4.

I watched several presentations on the Internet for each of them, and now I'm leaning towards WCF data services, mainly because of the filtering mechanisms built into the URI and the possibility of a built-in hyperlink. The only drawback I see is the verbosity of the Atom Pub specification, not the POX.

Is there anything I need to know about these two technologies before making a decision? Why does someone choose ASP.NET web API through WCF data services?

+84
rest odata asp.net-web-api wcf wcf-data-services
Feb 29 '12 at 17:44
source share
8 answers

This is a subjective question, so here is a subjective answer. IMO, WCF has too much overhead for simple RESTful services. The Web API, on the other hand, was designed specifically for RESTful services.

I agree with Dave Ward on this . Check out his blog for more information.

Ive opposed the pressure for a long time to switch from ASMX to WCF in WebForms Projects because accepting the complexity of WCF first of all rewarded me with less flexible JSON serialization. On the contrary, Ive started converting some of my projects from ASMX to Web API and was pleased with how easily the Web API replaces ASMX.

I believe that Microsoft has finally found a good balance between ASMXs simplicity and the power of WCF using the Web API.

+30
Feb 29 '12 at 17:50
source share

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 :)

+109
May 2 '12 at 6:18
source share

We believe that the web API provides the right platform for OData services, moving forward and, as such, will invest primarily in this platform for OData server stacks. Of course, we will continue the resources in the main libraries and the OData client, but we plan to reduce the investment in WCF data services as a stack for creating OData services.

OData Group Blog

So it seems now everything is clear enough

+26
Mar 22 '14 at 15:22
source share

Both Web APIs and WCF Data Services support OData out of the box. Using WCF Data Services (WCFDS), it is automatic. Using the Web API, return IQueryable from your controller and mark the [Queryable] method. This will give you the $filter functionality you were talking about. And if you do, both can automatically handle JSON in the response by putting accept=application/json in the request header. OData from WCFDS supports several OData keywords than the web API (although I only think of the $expand keyword), but I'm sure time will fix it.

Both .NET clients and HTML pages can easily access both alternatives, but if you like LINQ and build .NET clients, WCFDS can be added to your project as a reference service. This allows you to completely skip the entire HTTP project and directly request collections.

The bottom line is that you have nothing to put .svc files in your ASP.Net MVC project. This is not the same proposal. Adding data services to your server eliminates the need to write many controllers, but it does not stop you from writing additional controllers if you want.

+16
Jul 18 2018-12-18T00:
source share

In other words:

If you want to quickly find a data model (EDM or otherwise) and don't need a lot of code or business logic, WCF data services make this REALLY easy and be a good starting point.

If you are creating an API and just want to expose some resources (and logic) using the syntax or formatting of the OData request, then it is probably best to create an ASP.NET Web API .

http://mattmilner.com/Milner/Blog/post/2013/04/02/WCF-Data-Services-and-Web-API-with-OData;-choices-choices.aspx

+6
Jul 08 '13 at 7:13
source share

Devaron gave the most informative WCF review against Web Api that I have yet to find. Thank you Now that WCF is too complex, I will say that complexity is not automatically negative. You will be grateful for the breathing room that she will provide you in the future. The challenge, as always, with Microsoft tools is that we don’t know or control this future. Let me hope that Microsoft will finish working with a more unified system and that it will work for several years.

I also have a large build system, and this emphasizes to me that the path is no more clear. I plan to keep a couple more months until all this settles down. And personally, I'm rooting for datajs (also check out JayData)

+4
Jun 23 2018-12-12T00:
source share

This is the answer of TL, DR to this question.

WCF is a Swiss Army WEB API screwdriver knife for data transfer and transfer: WCF can do everything the WEB API can do, but if you need more (for example, using the TCP protocol), WCF is the way to go.

Here is a great comparison .

WEB API

One of the reasons for using the WEB API is that it is lightweight. This means that it is easier to implement, easier to learn, easier to maintain, etc. It is specifically designed for the Internet, which requires RESTful web services over HTTP. He does it, and he does it well. If that's all you need, the WEB API is probably the way to go.

Also, this is Open Source (if you're interested)

WCF

WCF just does a lot more than WEB API: it supports several transfer protocols, several exchange patterns (WEB API requires integration with SignalR or web sockets), SOAP services can be described in WSDL, they have additional security features and much more. Go with WCF if you need additional features.

OData h2>

OData is just

An open protocol that allows you to create and use requested and compatible RESTful APIs in a simple and standard way. source: http://www.odata.org/

In other words, a high level is simply the standardization of a specific grammar for RESTful HTTP requests. This will provide the same benefits as any protocol. And at least 2013 and the WCF and WEB APIs allow the use of OData. Therefore, you probably should not worry about OData.

0
Jun 17 '16 at 15:38
source share

Just do it in a simple way, step back from the base protocol and look at it from the point of view of the developer / user. The Web API is the first HTTP class, based on an HTTP basis, not WCF. This means the absence of any missing features, specifications that they are going to add to the web API, and not necessarily for WCF.

Yes, you can implement them yourself in WCF, but as the proposal says, you need to implement them yourself.

As an example, today, implementing two-factor authentication for the web API takes less than 15 minutes using OWIN, which is basically a nuget authentication / authorization package that runs as an open source project.

Using the technology stack is of utmost importance to use the first-class stack for Microsoft. You would even have countless published MS samples and projects on Github that you can simply copy and start on your own project. It matters at every level, documentation, code samples, feature set, support, helper you call.

So, my simple advice is if you want to create Restfull HTTP applications, use the web API (or ASP.NET Core for portability), and really don’t interfere with WCF. If the protocol is not HTTP, and it really cannot be HTTP, then use WCF.

0
Sep 08 '17 at 21:24
source share



All Articles