需要最少文件来部署的WebAPI服务器端 [英] Minimum files needed to deploy webAPI server side

查看:500
本文介绍了需要最少文件来部署的WebAPI服务器端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以经过研究大量的我开始加强与一的WebAPI切入点服务的服务器堆栈。基于这个线程,并通过数字文人董事会成员尤其是最后一篇,我们正在实施的WebAPI服务作为立面到我们的WCF应用层。 (我们的WCF服务只是门面到我们的应用层,所有的行为都生活)

我的问题是这样的。我下载MVC 4,在我的服务解决方案创建了一个新的WebAPI项目。但是WOW里面的是,在我的项目中创建一吨的废话,我只是我不会需要!例如,所有的图像文件,所述家用控制器,观点和模型等的

因此​​,在剥离下来到只是一个服务项目,什么是我需要建立一个功能性服务项目的最低文件?我们的意图是并排在同一服务器..每个服务呼叫做同样的相同服务调用和返回的具体DTO的请求来发布的服务类型(WCF和的WebAPI)侧。到目前为止,它看起来像App_Start,控制器,以及Glabal.asax / web.config中的条目。我绝对不需要查看,模型或图像!!!

这是别人做了做一个纯粹的服务部署任何投入将是巨大这里欢迎。


解决方案

在这里同样的问题。我发现, <一个href=\"http://www.visuallylocated.com/post/2012/05/10/Creating-a-minimal-Web-API-web-project.aspx\">article从肖恩Kendrot解释了如何创建最小的Web API项目。它是用于Web API的测试版,但写的好像是仍然有效。


  1. 创建一个空的ASP.NET项目。

  2. 添加引用 System.Web.Http System.Web.Http.WebHost (4.0版本。 0.0)

  3. 添加的Global.asax 文件

  4. 注册在 Global.Application_Start 的路线。是这样的:

     保护无效的Application_Start(对象发件人,EventArgs的发送)
    {
        GlobalConfiguration.Configuration.Routes.MapHttpRoute(
            名称:DefaultApi
            routeTemplate:API / {}控制器/(编号),
            默认:新{ID = RouteParameter.Optional});
    }


  5. 添加控制器

     公共类SampleController:ApiController
    {
      公共字符串GET(INT ID)
      {
        返回你好;
      }
    }


    1. 使用网址本地运行该项目/ API /样品/ 123 并享受成果:


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.

解决方案

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:

这篇关于需要最少文件来部署的WebAPI服务器端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆