Issue with ASP.net “Building a Restful API with ASP.Net Web API” tutorial…

I’ve been working my way through this tutorial, and found a mistake: http://www.asp.net/web-api/tutorials/hands-on-labs/build-restful-apis-with-aspnet-web-api

In Exercise 1, when creating your first Read-Only Web API, there’s something that isn’t mentioned and it should be.  When creating the ContactController class, it isn’t specified, but it needs to inherit from ApiController, not just Controller.  This also means that you will need to add “using System.Web.http” to the using statements.  Basically, it should look like this:

Image

Without those two lines, you won’t get a response (instead you’ll get a 404, and you won’t be able to see the details of the response).  Unfortunately there’s no comments allowed on the article, as this could be a ‘gotcha’ to other people trying to work through it.  The downloadable samples that they provide do work, but it’s nice to know what is causing the problem, rather than having to download and start working with someone else’s code. 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s