6

I am creating a new ecommerce application in MVC and sql server as database.I want to use Entity framework for the same. I am confused in selection of my data access layer. Which one should I use among WCF vs Web api vs Web services. It may be possible that in future we may required android and IOS app. I think Web api will be the best option for this.

I try to find the difference between web api and WCF, what did i found is that. 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. There are thousand of links telling about Rest, TCP, FTP, soap, Http. But no where I found my answer. I am still confused Which one will fulfill my problem. One more thing if I choose Web api, can entity framework integrate with Web api. I am new to dot net. any help will be very helpful.

Edit: @win thanks for your help. I want to know, How to decide which one should i choose, RESTFull(Web api) or WCF(Soap). Which factors in application decide, which one to use.

Nimish goel
  • 2,561
  • 6
  • 27
  • 42
  • 1
    i hope you can get your answer in another question posted in stackoverflow [here](http://stackoverflow.com/questions/9348639/wcf-vs-asp-net-web-api) – Shafqat Masood Feb 23 '16 at 13:57
  • Thats depends on what you are going to create, what you need and expect from your core api. You can both get REST and Web Services feature with WCF plus WCF is a platform which you can make deep customizations. Web Api and Web Services are lighter than WCF but you shoul decide that within your needs. – Cihan Uygun Feb 23 '16 at 13:59
  • 1
    **Entity Framework** is nothing to do with **Web API** and **WCF**. If you need to support both **SOAP** and **REST**, use **WCF**. Otherwise, use **Web API**. If you are new to Web API, [ASP.NET Web API 2: Building a REST Service from Start to Finish](http://www.amazon.com/ASP-NET-Web-API-Building-Service/dp/1484201108/ref=sr_1_1?ie=UTF8&qid=1456236356&sr=8-1&keywords=web+api+start+to+finish) will guide you to build Web API step-by-step *(Note: It uses NHibernate for Data Access Layer, but you can change it to Entity Framework easily)*. – Win Feb 23 '16 at 14:03
  • @Win thanks for your help. Can you help me to know the basic difference between Soap and Rest. My main point is the basic requirements for application. How to decide what do I need SOAP or REST OR both. – Nimish goel Feb 23 '16 at 14:37
  • @CihanUygun thanks for your help, But can you clear me what features will I missed If i choose Web api as compare to WCF. Because I am good with Web api and will Prefer WCF. – Nimish goel Feb 23 '16 at 14:39
  • Are you _building an API_ to be used by clients externally? Otherwise, your internal structure should help you get to your decision - e.g. if you have SOAP clients, then you'll probably need to support it, etc. Hth... – EdSF Feb 23 '16 at 16:33
  • @user2810015 ***I'm closing this question, as it ends up being [WCF vs Web API](http://stackoverflow.com/questions/9348639/wcf-vs-asp-net-web-api) and [SOAP vs REST](http://stackoverflow.com/questions/19884295/soap-vs-rest-differences) which were already answered in SO.*** – Win Feb 24 '16 at 00:11

1 Answers1

9

WCF provides a lot of functionality, but at the cost of crazy-mad configuration setup. Crazy mad. It involves defining an "ABC", Address, Binding, Contract. I always tell people "with WCF: its the configuration, not the code". There are just ~so many options for configuring it.

If you need to push/pull small amounts of data to "clients" (browser, android, iphone), then WebApi is the best bet.

One feature, WebApi will give you xml OR json via how the request is setup (in the 'header').

With WCF, you have to "code up" either/or/both for json and xml and it isn't super trivial. Aka, you have to put attributes on the Service-Methods (the "Contract" of the ABC) to say "this method will send back xml" or "this method will send back json".

Your WebApi layer will provide services. This usually means providing json data or consuming json data. And MS has taken care of the "plumbing" for you, so on the services side, this happens auto-magically.

I've coded both since 2005 (well, WCF in 2005 and following, and then later with WebApi).

WebApi is much easier to deal with, especially for a beginner.

So unless you have a very concrete reason to use WCF, I would use WebApi.

As far as an ORM, that happens completely on the "server side", so you can pick whichever one you want. I would pick Poco/Code-First/Entity-Framework OR NHibernate (for "full" ORM's) or Dapper (for a micro ORM). Which ORM to use is a full discussion in itself. But quick advice, don't choose one willy-nilly, do a little research. Search things like "Entity-Framework vs NHiberate" or "Entity-Framework vs ADO.NET" or "Dapper vs NHiberate" (you get the drill, any combination, and sometimes you'll find a comparison that does all three plus others.

Here is a little explanation of the auto-magic wire up...where you are not hand-parsing json on the SERVER side.

http://encosia.com/using-jquery-to-post-frombody-parameters-to-web-api/

and here

http://encosia.com/rest-vs-rpc-in-asp-net-web-api-who-cares-it-does-both/

Outside of my opinions here, here is a Microsoft comparison article :

https://msdn.microsoft.com/en-us/library/jj823172.aspx

and the quote:

Use WCF to create reliable, secure web services that accessible over a variety of transports. Use ASP.NET Web API to create HTTP-based services that are accessible from a wide variety of clients. Use ASP.NET Web API if you are creating and designing new REST-style services. Although WCF provides some support for writing REST-style services, the support for REST in ASP.NET Web API is more complete and all future REST feature improvements will be made in ASP.NET Web API. If you have an existing WCF service and you want to expose additional REST endpoints, use WCF and the WebHttpBinding.

granadaCoder
  • 26,328
  • 10
  • 113
  • 146
  • Somebody who thought about it a lot more than I did : http://blogs.microsoft.co.il/idof/2012/03/05/wcf-or-aspnet-web-apis-my-two-cents-on-the-subject/ – granadaCoder Feb 23 '16 at 19:55