>我可以实现我过去使用MVC实现的任何功能;使用新的Web API并采用更轻量级的方法.
>使用Web API比较asp.net MVC更容易开发Web服务.
那么,asp.net Web API将来是否会接管asp.net MVC,或者每种技术都有自己的增长领域,或者我们是否应该考虑在同一个Web应用程序中使用它们?
解决方法
关键是要了解每种技术的目标:
> Web API.
这将是用于创建Web服务的新API,这是传统XML服务和WCF服务的替代方案,因此值得首先指出WEB API与其他Web服务框架之间的主要区别.
Web API和WCF / ASMX服务之间的主要区别在于它不基于SOAP它基于HTTP因此您可以利用所有HTTP功能,例如:
>它包含非常有意义和描述性的邮件标题 – 表示邮件正文内容类型的标题,解释如何缓存信息的标题,如何保护信息等.
>使用动词来定义动作(POST,PUT,DELETE ..)
>它包含一个可用于发送任何类型内容的正文
>它使用URI来识别信息路径(资源)和操作
That was the main goal of the Web APIs,known back then as the WCF Web APIs: to stop looking at HTTP through the eyes of WCF – as just a transport protocol to pass requests. Rather,it allows us to look at it as the real application-level protocol it is – a rich,interoperable,resource-oriented protocol. The purpose of the Web APIs was to properly use URIs,HTTP headers,and body to create HTTP services for the web,and for everyone else that wished to embrace HTTP as its protocol and lifelong friend.
有关更多信息,请查看本文:http://www.codeproject.com/Articles/341414/WCF-or-ASP-NET-Web-APIs-My-two-cents-on-the-subjec
因此,基本上可以将Web API与WCF或XML服务进行比较
如果您想知道WCF将会发生什么?
So the fact was we had too many options and therefore too much confusion. What were we to do? We merge teams! (Kind of reminds us of the time of LINQ-to-sql and Entity Framework,WCF and Ado.Net Data Services and other such examples). So the WCF team and the ASP.NET team joined forces and created a new framework focused on the world of REST/Hypermedia/HTTP services for the web world and thus came out the ASP.NET Web APIs.
> MVC
既然您知道Web API的目标是什么,那么应该更容易说明为什么MVC包含主要呈现视图的附加功能.
您的担忧是基于WEB API实际上基于MVC的事实,但他们的目标是不同的
On the other hand,the ASP.NET MVC infrastructure with its elegant handling of HTTP requests and responses,and its support of easy-to-create controllers seemed like the proper way to go for creating this new type of services