Question

So after a great deal of research I'm starting to enhance our service server stack with a webAPI entry point. Based on this thread, and especially the last post by a member of the Digerati board, we are implementing webAPI services as a facade into our WCF application layer. (Our WCF services are just facades into our Application layer where all of the behavior lives)

My question is this. I downloaded MVC 4 and created a new WebAPI project in my service solution. But wow there was a ton of crap that created in my project that I just am not going to need! For example, all of the image files, the home controller, views and models, etc.

So in stripping this down to be just a service project, what are the minimum files I need to build a functional service project? Our intent is to publish both of the service types (WCF and webAPI) side by side in the same server .. each service call doing the same identical service call and returning the specific DTO for the request. So far it looks like App_Start, Controllers, and the Glabal.asax/web.config entries. I definitely don't need Views, Models, or Images!!!

Any input on what others have done to do a pure service deployment would be of great welcome here.

Was it helpful?

Solution

Same problem here. I've found that article from Shawn Kendrot explaining how to create minimal Web API project. It was written for the beta version of Web API but it seems to be still valid.

  1. Create an empty ASP.NET project.
  2. Add a reference to System.Web.Http and System.Web.Http.WebHost (version 4.0.0.0)
  3. Add a Global.asax file
  4. Register a route in the Global.Application_Start. Something like:

    protected void Application_Start(object sender, EventArgs e)
    {
        GlobalConfiguration.Configuration.Routes.MapHttpRoute(
            name: "DefaultApi",
            routeTemplate: "api/{controller}/{id}",
            defaults: new { id = RouteParameter.Optional });
    }
    
  5. Add a controller

    public class SampleController : ApiController
    {
      public string Get(int id)
      {
        return "Hello";
      }
    }
    
    1. Run the project locally with the URL /api/sample/123 and enjoy the outcome:

enter image description here

OTHER TIPS

FYI. I have found that I have had to reference two more .dlls:

  • System.Net.Http
  • Newtonsoft.Json
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top