Solved

C# Rest Web Services API can only be created using asp.net MVC?

Posted on 2015-01-12
11
200 Views
Last Modified: 2015-01-15
Hi, I'm using VS2012.  
I need to create a Rest Web Service program that will consume another web service to get data, re-package it then provide as a web service to another program with this new packaged/formatted data.  
Is the only way to do this in C# is using the MVC model?
I did find a couple of project templates in VS when I click to start new project, "Web Form web API application project template" and "ASP.net MVC Boilerpate".  Which template should I use?
Thank you.
0
Comment
Question by:lapucca
  • 4
  • 4
  • 3
11 Comments
 
LVL 35

Expert Comment

by:Miguel Oz
ID: 40545429
Actually you can select Web API project from ASP.NET MVC 4 project type dialog, select the as shown here:
http://www.asp.net/web-api/overview/older-versions/build-restful-apis-with-aspnet-web-api
0
 
LVL 9

Expert Comment

by:sudheeshthegreat
ID: 40545585
ASP.NET Web API and WCF are the 2 main ways in which you can create ReSTful services with C# now. There are other ways too, but you probably dont want to unless there are reasons these frameworks cannot provide you with what you need.
0
 

Author Comment

by:lapucca
ID: 40549699
Which is most used now to create REST API?  ASP.NET MVC API or WCF?
So, web api cannot be created using a regular asp.net project template?  It has to be asp.net MVC project template and then select WEB API?

Thank you.
0
 
LVL 9

Accepted Solution

by:
sudheeshthegreat earned 250 total points
ID: 40549811
WCF has been around for years since .NET framework 3.0. It is tried and tested, and the good thing about it is that you can simply expose a new endpoint for your service using WebHttpBinding and add some attribute to your service contract for REST Uri paths, and that will give you a RESTful service. If you feel later on that SOAP is better, or that you want to provide both SOAP and REST, you can still do that in WCF.

On the flip side, if you want to provide specific HTTP response codes, such as a 404 or a 503, I am not saying it cant be done in WCF, but ASP.NET Web API makes that simpler. ASP.NET Web Api is fairly recent, and its USP is that it makes it easier to create HTTP web services, and so, if you are building a new RESTful service, this seems to be the future.

I just realized that MSDN also has a page to compare these 2.
http://msdn.microsoft.com/en-us/library/jj823172(v=vs.110).aspx
0
 

Author Comment

by:lapucca
ID: 40549864
Sud, thank you for that break down analysis and the link.  Just one last  question.  Since I'm writing new RESTFUL APIs so I will go with the ASP.NET WEB API , so I have to do this in ASP.NET MVC?  Or can I do this using a ASP.NET web project template?  I mean, when I create a RESTFUL project, what option do I have in Visual Studio 2012 as to what project templates should I use if I'm going with ASP.NET Web API.
Thank you.
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 9

Expert Comment

by:sudheeshthegreat
ID: 40549915
The project templates are a bit different depending on which editor / IDE you use.

With Visual Studio 2013, there's a project template for ASP.NET Web Application, which further lets you choose one or more of Web Forms, MVC, Web API, and so on. So, in your case, you just need to create a project using the ASP.NET Web Application template, and select Web API.

ASP.NET MVC is typically used for creating a website, not a web service. Although there isnt anything stopping you from sending back non-html content (such as json or xml) for all the controllers' actions in MVC either.
0
 
LVL 35

Assisted Solution

by:Miguel Oz
Miguel Oz earned 250 total points
ID: 40549975
As previously stated in my early post, you can select Web API project from ASP.NET MVC 4 project type dialog.
 ASP.NET MVC4 is already included in VS2012,  a gpod example that includes sample code is shown in this link
0
 

Author Comment

by:lapucca
ID: 40550066
I haven't developed in ASP.NET MVS for over 5 years and would rather stick with good old ASP.NET project if I can.  I'm using VS2012 however, I did download the VS2013 but I think that is just the Beta version, can I use VS2013 or should I?  Thank you.
0
 
LVL 35

Expert Comment

by:Miguel Oz
ID: 40550081
It is actually easier to work with web api over WCF for REST web service and it can be consumed using C# or Jquery AJAX. There is no need to use MVC constructs if you just want to build a Web API project containing the web service
You do not need VS2013 to use Web api as per info in the links.
0
 
LVL 9

Expert Comment

by:sudheeshthegreat
ID: 40550232
Better to use VS2013 Community Edition.
0
 

Author Closing Comment

by:lapucca
ID: 40551663
thank you both for your great input.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now