Abs
Abs

Reputation: 57916

Building a C# Web API - REST

I am about to start a project in C#. I've never used c# and I was hoping I could get some implementation advice before I make a silly mistake and go down the wrong path.

What I am trying to achieve is basically having a C# application on a server that can be accessed via a Web API. This application will take in some string variables and then return a string. The application will be opening and running some installed programs (not c# programs).

I've read about WCF but I think at first glance this might be overkill as the API I am hoping to create will only have one or two request methods and will return a string.

What I am really looking for is advice on what I should be using, what to look into and even links to good tutorials on building web services with C# and how I can make the link between a web API to a C# app.

Thanks all for any advice.

Upvotes: 7

Views: 8445

Answers (5)

Derek Beattie
Derek Beattie

Reputation: 9478

If you think WCF might be overkill you could implement a simple ASP.NET MVC application that returns data as JSON or XML.

http://omaralzabir.com/create_rest_api_using_asp_net_mvc_that_speaks_both_json_and_plain_xml/

update: Another excellent option is ServiceStack. I've used it and it's really nice to work with.

Upvotes: 4

Rebecca
Rebecca

Reputation: 14402

For a simple Web API, WCF is overkill, clunky, operation orientated and designed for SOAP based services (it does Web HTTP, but that was an afterthought).

The new kid on the block is ASP.NET MVC Web API for lightweight web-orientated architectures. Prepare to see more and more of this young upstart.

Upvotes: 1

ChrisLively
ChrisLively

Reputation: 88044

Skip wcf and asmx. Instead just implement this stuff through generic handlers (.ashx) files.

You have complete control over what comes in and goes out without having to muck around with all the XML garbage. We did this a while back and haven't looked back.

In short, I'd use WCF if my endpoints were going to be something other than the web server. I'd use asmx if I had to deliver all of the responses back as XML AND I was assured only .net clients would be accessing it.

Generic handlers are like .aspx pages but without all of the overhead of the page lifecycle. It gives you get a context object that has access to all of the http post and query string variables and it's up to you to decide what to emit back.

They are simple to implement and have none of the "what was that config setting for again?" issues.

Here are a couple pretty good walkthroughs:
http://swindelles.com/2008/07/11/creating-rest-web-services-in-c-sharp/
http://www.codeproject.com/KB/aspnet/RestServicesInASPNET2.aspx

Upvotes: 9

Rob Alarcon
Rob Alarcon

Reputation: 1450

You really need to take a look to the WCF Data Services they are easy to implement

http://msdn.microsoft.com/en-us/data/bb931106

I first met them when I implemented the Dino Esposito examples in March 2010 MSDN Magazine http://msdn.microsoft.com/en-us/magazine/ee336022.aspx

I recommend you first read the Dino Example.

Upvotes: 1

David Ly
David Ly

Reputation: 31586

You could look into vanilla web services. I only briefly glanced at it, but this seems like a decent guide.

Upvotes: 1

Related Questions