ASP.NET WebApi 与 MVC? [英] ASP.NET WebApi vs MVC?

查看:21
本文介绍了ASP.NET WebApi 与 MVC?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 ASP.NET MVC 控制器,您可以以不同的格式公开您的数据.AspNetWebAPI 是为创建 API 明确设计的,但我可以使用 MVC 控制器轻松做到这一点,我不清楚在什么情况下它会比传统的 MVC 控制器更好.我对 WebApi 的好处显而易见并且值得为我的应用程序添加另一个复杂层的场景感兴趣.

问题:与 MVC 相比,使用 asp.net WebApi 有哪些优点和/或缺点?

解决方案

WebApi 允许创建可以通过 HTTP 而不是通过正式服务(如 WCF 或 SOAP)公开的服务.另一个区别在于 WebApi 如何使用 Http 协议并使其成为真正的一流 Http 公民.

更新: ASP.NET Core、Web API 已集成到 MVC 项目类型中.ApiController 类合并到 Controller 类中.更多信息:

With ASP.NET MVC controllers you can expose your data in different formats. AspNetWebAPI is designed explicitly for creating API's but I can easily do that with MVC controllers, is not clear to me in what cases it would be better than traditional MVC controllers. I'm interested in scenarios where the benefits of WebApi are obvious and it would be worthy to add another complexity layer to my applications.

Question: what are the advantages and/or disadvantages of using asp.net WebApi in respect to MVC ?

解决方案

WebApi allows to create services that can be exposed over HTTP rather than through a formal service such as WCF or SOAP. Another difference is in the way how WebApi uses Http protocol and makes it truly First class Http citizen.

UPDATE: The ASP.NET Core, Web API has been integrated into MVC project type. The ApiController class is consolidated into the Controller class. More at: https://wildermuth.com/2016/05/10/Writing-API-Controllers-in-ASP-NET-MVC-6

A relevant link of comparison, discussions & tutorials:

这篇关于ASP.NET WebApi 与 MVC?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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