In Visual Studio 2012, follow these steps to add a new ASP.NET Web API project to the existing DrDobbsApp solution:
- Select File | Add | New Project… The Add New Project dialog box will appear.
- Select Templates | Visual C# | Web in the left pane. The templates list will display many templates for the selected target, including ASP.NET MVC 4 Web Application.
- Select ASP.NET MVC 4 Web Application and enter the desired name in the Name textbox. I'll use
DrDobbsAppWebAPI. - Click OK and the New ASP.NET MVC 4 Project dialog box will appear. Select the Web API template and click OK (see Figure 5). Visual Studio will create a complete ASP.NET Web API project.
- Go to the new project (
DrDobbsAppWebApi), right click on References, and select Add Reference… The Reference Manager dialog box will appear. Click on Solution | Projects in the left pane, checkDrDobbsApp.Entities( Figure 6) and click OK. This way, the ASP.NET Web API project can use the entities defined in the Portable Class Library. - The ASP.NET Web API project includes two default controllers:
HomeControllerandValuesController. Add a new controller to the ASP.NET Web API project in the Controllers folder, as you do in classic ASP.NET MVC projects. Add a new GroupsController controller with the Empty API controller template (see Figure 7).
Figure 5: The New ASP.NET MVC 4 Project dialog box allows you to select a project template.
Figure 6: Adding the reference to the Portable Class Library in the ASP.NET Web API project.
Figure 7: The Add Controller dialog box allows you to select different templates tweaked for ASP.NET Web API project, such as the Empty API controller.



