Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC API or WCF API

I'm developing an ASP.NET MVC 3 application. I need this application to make use of an API I also need to implement. The API should both be available from ASP.NET MVC controller actions and Ajax. Now it is quite easy to make an API using ASP.NET MVC, but is it possible to use this from other ASP.NET MVC website actions? I guess the WCF is quite easy to use as it is just a service reference.

Other users of the API could be Windows Phone and iPhone.

Update:

Many only sees the API as a place where you consume data, but what about the part where you want to execute commands or do stuff, like add customer or change foo?

like image 668
Rasmus Christensen Avatar asked Apr 27 '11 19:04

Rasmus Christensen


2 Answers

You may want to check our new WCF web API that was announced at PDC. We recently released a big upgrade. WCF Web API is designed specifically for allowing you to expose APIs to a range of clients in a pure HTTP manner. It is lightweight, offers a nice configuration story (no configuration files) and also is much easier to test.

You can download the bits at wcf.codeplex.com. It includes various samples, and there is also a set of NuGet packs for getting you started. Search for webapi.all on NuGet.

like image 113
Glenn Block Avatar answered Oct 13 '22 06:10

Glenn Block


The way I like to do this is with RESTful controller actions. You can return JSON and use your calls with JavaScript on your own site. Other websites would almost certainly understand JSON and so they'd be able to consume your API pretty easily. This is much easier to write and test than a heavy WCF layer.

Check out this question for some example REST frameworks for MVC:

ASP.NET MVC REST frameworks

like image 20
Milimetric Avatar answered Oct 13 '22 05:10

Milimetric