Solved

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

Posted on 2015-01-12
11
207 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 36

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
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 
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
 
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 36

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 36

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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

762 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