【问题标题】:Difference between Web API and Azure API APP in Visual StudioVisual Studio 中 Web API 和 Azure API APP 的区别
【发布时间】:2018-05-28 21:21:36
【问题描述】:

在创建新的 ASP.NET Web 应用程序以开发我的 API 并将其托管在 Azure 中时,我有两个选择:

  • 网络 API
  • Azure API 应用程序

我可以创建一个 Web API APP 并将其托管在 Azure API APP 中吗?那么它们都存在的主要原因是什么?

【问题讨论】:

    标签: asp.net azure asp.net-web-api2 azure-api-apps


    【解决方案1】:

    您可以查看link

    Azure 应用服务中的 API 应用提供的功能可让您更轻松地在云端和本地开发、托管和使用 API。借助 API 应用,您可以获得企业级安全性、简单的访问控制、混合连接、自动 SDK 生成


    Web 应用是 Azure 提供的用于在应用服务中托管网站或 Web 应用程序的计算资源。计算资源可能位于共享或专用虚拟机 (VM) 上,具体取决于您选择的定价层。您的应用程序代码在与其他客户隔离的托管 VM 中运行。

    【讨论】:

    • 我在问Visual Studio中两个模板的区别(web Api和azure api我没有提到Web APPs)。根据 Azure API Apps 和 Web Apps,我相信它们是相同的,并且提供相同的功能,它们之间唯一的区别是图标。
    • @Coding 实际上,Azure API 应用程序是一种网络应用程序。
    【解决方案2】:

    Web API - 此样板将在同一解决方案中生成 MVC(Model/View/Control) 模式(Web App) 和 Web API 的模板。

    Azure API 应用程序 - 此样板将生成 Web API 模板,不包括 Web 应用程序的相关文件。它在 app_start 下还有一个名为 SwaggerConfig.cs 的额外配置文件。
    here: ASP.NET Core Web API help pages with Swagger / Open API。将 API 发布到 azure 时会很有帮助。

    【讨论】:

      【解决方案3】:

      它们只是不同的起点,具体取决于您的需求。

      Azure API 是一个精简的仅 API 模板,支持 OpenAPI。

      ASP.NET Web API 是一个完整的 ASP.NET MVC 应用程序,主要用于支持 API。

      差异 #1:Web API 模板中的身份验证支持

      ASP.NET Web API

      支持身份验证选择(无、个人用户、工作或学校、Windows)。

      ASP.NET Azure API 应用程序

      期望客户端提供令牌(不记名令牌或 API 令牌)。使用 Azure 门户配置用户(不是 API 令牌)的身份验证和授权。使用 Azure API 管理(或其他服务)来管理 API 令牌。

      区别 #2:Web API 模板中的 MVC 支持

      ASP.NET Web API

      自动包含 MVC 以显示帮助页面。这些与 OpenAPI (Swagger) 自行生成的文档不同。

      ASP.NET Azure API 应用程序

      不会自动包含 MVC 或帮助页面

      区别 #3:Web API 中的 UI 支持文件

      ASP.NET Web API

      包括区域、内容、HomeController、字体、脚本和视图

      ASP.NET Azure API 应用程序

      区别 #4:Web API 模板中的更多启动配置

      ASP.NET Web API

      public class WebApiApplication : System.Web.HttpApplication
      {
          protected void Application_Start()
          {
              AreaRegistration.RegisterAllAreas();
              GlobalConfiguration.Configure(WebApiConfig.Register);
              FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
              RouteConfig.RegisterRoutes(RouteTable.Routes);
              BundleConfig.RegisterBundles(BundleTable.Bundles);
          }
      }
      

      ASP.NET Azure API 应用程序

      public class WebApiApplication : System.Web.HttpApplication
      {
          protected void Application_Start()
          {
              GlobalConfiguration.Configure(WebApiConfig.Register);
          }
      }
      

      差异 #5:Azure API 模板中的 OpenAPI (Swagger) 支持

      ASP.NET Web API

      public class ValuesController : ApiController
      {
          // GET api/values
          public IEnumerable<string> Get()
          {
              return new string[] { "value1", "value2" };
          }
      
          // GET api/values/5
          public string Get(int id)
          {
              return "value";
          }
      
          // POST api/values
          public void Post([FromBody]string value)
          {
          }
      
          // PUT api/values/5
          public void Put(int id, [FromBody]string value)
          {
          }
      
          // DELETE api/values/5
          public void Delete(int id)
          {
          }
      }
      

      ASP.NET Azure API 应用程序

      OpenAPI (Swagger) 默认启用。 OpenAPI JSON 文档位于 /swagger/docs/v1

      public class ValuesController : ApiController
      {
          // GET api/values
          [SwaggerOperation("GetAll")]
          public IEnumerable<string> Get()
          {
              return new string[] { "value1", "value2" };
          }
      
          // GET api/values/5
          [SwaggerOperation("GetById")]
          [SwaggerResponse(HttpStatusCode.OK)]
          [SwaggerResponse(HttpStatusCode.NotFound)]
          public string Get(int id)
          {
              return "value";
          }
      
          // POST api/values
          [SwaggerOperation("Create")]
          [SwaggerResponse(HttpStatusCode.Created)]
          public void Post([FromBody]string value)
          {
          }
      
          // PUT api/values/5
          [SwaggerOperation("Update")]
          [SwaggerResponse(HttpStatusCode.OK)]
          [SwaggerResponse(HttpStatusCode.NotFound)]
          public void Put(int id, [FromBody]string value)
          {
          }
      
          // DELETE api/values/5
          [SwaggerOperation("Delete")]
          [SwaggerResponse(HttpStatusCode.OK)]
          [SwaggerResponse(HttpStatusCode.NotFound)]
          public void Delete(int id)
          {
          }
      }
      

      【讨论】:

        猜你喜欢
        • 2017-04-11
        • 1970-01-01
        • 2015-12-07
        • 1970-01-01
        • 2012-03-16
        • 2017-01-13
        • 1970-01-01
        • 1970-01-01
        • 2013-10-15
        相关资源
        最近更新 更多