24

I'm going to be working on a project that involves a number of elements:

  • ASP.NET MVC website
  • C# console application
  • iPhone App

To get all these separate applications talking to the database, my immediate thought was to use a WCF Service.

However, I now need to add an API to the site to allow third parties to select, insert and update records from their own applications.

In my mind, I would just create a separate RESTful service endpoint on my WCF Service which would be locked down using authentication and would only give access to certain methods.

However, I've been reading today about the Web API feature in MVC 4 which is meant to be the latest thing for RESTful APIs?

Should I be going along the line of using the Web API? or because my other applications need a web service, should I stick with a WCF Service?

Dan Ellis
  • 5,537
  • 8
  • 47
  • 73
  • possible duplicate of [WCF vs ASP.NET Web API](http://stackoverflow.com/questions/9348639/wcf-vs-asp-net-web-api) – nawfal Oct 29 '14 at 23:00

6 Answers6

16

If you intend to do RESTful development then you will definitely want to use the ASP.Net Web Api (which was originally called WCF Web Api and created with the goal of "Making REST a first class citizen in .NET".

Another thing to consider is that the WCF REST Starter kit is no longer supported.

Note that using Web Api doesn't mean you have to use ASP.Net MVC or IIS even as it can be self hosted.

For handling operations which are non-CRUD in nature I'd recommend Googling "REST non-CRUD". I found this blog post RESTful URLs for non-CRUD operations (and particularly the comments interesting). If you decide you NEED to have RPC calls then those may have to be done with WCF. That said since WCF REST is being killed off I'm not sure what the best solution is going to be. Having both is probably the best answer but at the same time it's not necessarily a good answer.

Another alternative would be a WCF OData Service but I'm not sure if that gets any support from an iPhone.

One last point to make (that can be deleted in the future as this is time sensitive)

Microsoft has provided a Go Live license with the beta which means that it is supported by Microsoft and you shouldn't have any problems upgrading to the file RTM.

Shane Courtrille
  • 13,960
  • 22
  • 76
  • 113
  • Thanks for your comment. Surely because I'm going to be using the service/api for my MVC website too, I wouldn't want the entire service/api to be RESTful? Is that possible with the Web API? I know with a WCF Service you can have seperate endpoints for RESTful – Dan Ellis Mar 01 '12 at 10:23
  • Added additional info to post. – Shane Courtrille Mar 01 '12 at 15:49
  • I don't fully understand your additional info. Would a solution be to use a WCF service which I can reference from my MVC website. Then I could use a Web API (with authentication) which also communicates with the WCF service to get the data? – Dan Ellis Mar 01 '12 at 17:25
  • Do you NEED to have a SOAP based RPC styled service that people can use? Or could you instead supply RESTful urls that allow for the same operations.. as discussed in the RESTful URLS for non-CRUD operations blog post comments? If you can get away with staying pure RESTful it's probably worth it so you don't have the complexity of WCF. If you need WCF then you need WCF and you should probably use Web Api for the things you decide should be RESTful... – Shane Courtrille Mar 01 '12 at 17:36
  • Sorry, I'm getting a bit lost in the wording. If I went with a Web API, am I able to add it as a service reference for my MVC website which will be able to access a load of methods to communicate with my database. Am I then able to have a separate part of the Web API which I can make open to the outside world and have authentication on? – Dan Ellis Mar 01 '12 at 17:43
  • @Scrooby: Yes, you can do that. – Sunny R Gupta Jan 04 '13 at 05:07
6

Service Stack also looks like an option.

Demos, overview, examples is available here.

Dima Pasko
  • 1,170
  • 12
  • 20
  • 2
    +1 for mentioning Service Stack, which I'd never heard of. Looking over their framework, however, my first impression is that their stated goal of "no code-gen" for the client isn't entirely accurate. Code-gen (apparently manual) is still required if you do not have access to the service DTOs, which is a highly likely scenario for a public API. Still, the framework looks promising, so I'll definitely be studying it. Thanks for the link! – Randolpho Feb 29 '12 at 16:19
  • Nope there is no code-gen as you are able to re-use the same DTO's you defined your web services with. So you get a typed, succinct generic service clients that uses fast, versionable serializes end-to-end. Even the C# exceptions are idiomatic and typed https://github.com/ServiceStack/ServiceStack/wiki/Validation – mythz Mar 01 '12 at 05:46
  • @mythz and what if you don't have access to the .DLL that defined the DTOs? This is a common scenario with publicly accessible web services. – Randolpho Mar 02 '12 at 03:56
  • There is are WSDL/XSDs on the meta data pages so you can code-gen your models. You can parse them dynamically. You can create partial typed models on the client with the data you're interested in, You can ship a client library with Models + C# Service Clients. Because they're clean tech, you're not coupled to a single tool and you've got a tonne of options. – mythz Mar 02 '12 at 04:51
4

There's no right answer here. You can certainly do fairly well with a WCF RESTful service. Or you could use ASP.NET MVC. Both are perfectly valid, and both have strengths and weaknesses.

Ultimately, I'd suggest you go with whatever feels the most maintainable to you.

I would like to note that MVC 4 is in beta, so watch out for bugs and don't go live until it's out of beta.

Randolpho
  • 55,384
  • 17
  • 145
  • 179
1

I would be inlclined to look at what has the best support on all platforms that you are going to use, I suspect the iPhone app may end up driving your choices.

If it was pure .net I would still tend to lean toweards a SOAP service - it is not considered cool these days but it generally will do what you need on most platforms without having to roll custom solutions.

EDIT

ASP.NET Web API means that .NET now provides a great framework for developing a restful API, I revise my answer to say that I would now lean towards this - progress is great!

dice
  • 2,820
  • 1
  • 23
  • 34
1

Since you are going to create an ASP.NET MVC web site, it would be quite comfortable to use ASP.NET Web API also because programming model is very similar and those solutions are more or less integrated with each other.

paulius_l
  • 4,983
  • 8
  • 36
  • 42
0

I have the same question.

In the MSDN site, http://msdn.microsoft.com/en-us/library/jj823172(v=vs.110).aspx

Found a video tutorial where they said that for machine cosumption like iPhone or web app clients of JSON or xml, web API is recommended option. Its around the last part of the video.

While for more complex machine to machine communication WCF is prefereable.

http://channel9.msdn.com/Series/Building-Web-Apps-with-ASP-NET-Jump-Start/Building-Web-Apps-with-ASPNET-Jump-Start-04-Building-a-Service-Layer-with-ASPNET-Web-API

Here is a screenshot from their presentation.

enter image description here

karim
  • 15,408
  • 7
  • 58
  • 96