Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Minimum files needed to deploy webAPI server side

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.

like image 573
SASS_Shooter Avatar asked Sep 13 '12 18:09

SASS_Shooter


People also ask

Do ASPX files need to be compiled?

aspx. cs file) must first be compiled. This compilation can happen explicitly or automatically. If the compilation happens explicitly then the entire application's source code is compiled into one or more assemblies ( .


2 Answers

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

like image 83
Yann Trevin Avatar answered Oct 23 '22 07:10

Yann Trevin


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

  • System.Net.Http
  • Newtonsoft.Json
like image 29
Mark Lybrand Avatar answered Oct 23 '22 05:10

Mark Lybrand