[Reprint] Asp.net MVC and Asp.net Web API distinguish the difference between the MVC and WebApi

Asp.net MVC and Asp.net Web API differences

HTTPS: // www.cnblogs.com/viktor988/ 

HTTPS: // www.cnblogs.com/terry283618366/articles/5760297.html 

https://www.cnblogs.com/cjm123/p/8067109.html
need to learn some more things can.

 

When we develop some web applications, as we can use to return data in JSON MVC Framework in JsonResult, also can handle some simple AJAX request, then why Microsoft has launched a Web API do such a thing? Now let's compare. Both (Asp.net MVC and Asp.net Web Api) when to use?
 
1, Asp.net MVC is used to create Web application returns view (Views) with the data, while Asp.net Web API is a simple and easily mature HTTP service, it only returns the data, does not return view (Views). 
2, Asp.net Web API through .Net Framework can help us build REST-ful service, and he supports content negotiation (according to the format requires the client to accept, and returns the corresponding JSON, XML, ATOM), while Asp.net Web API supports self host (self-hosting), but MVC does not support (only host in IIS). 

3, Asp.net Web API may return specific data types, such as JSON, XML, or other request header in the data format defined. The MVC can only use Json Result return JSON data types. 

4, Asp.net Web API HTTP according to the verb to map Action, but only MVC map Action name. 

5, Asp.net Web API a new framework, which is part of Asp.net Framework core libraries. Some features in Asp.net Web API exist in MVC (model binding, filters, routing) exists System.Web.Http assembly, while the MVC is in existence System.Web.Mvc. Therefore, Web API can be used with Asp.net, you can also do a separate service layer. 

6, if the integration of Web API and MVC controller in a project for dealing with complex AJAX requests, which may return JSON, XML or other data format. This is self-host Web API (Web API self-hosting).

7, if the fusion MVC and Web API controller (controller), and the need to integrate authentication, then you need to create two filters (Filters), a MVC and the other Web API, because the two of them are not the same . 

8, in short, WebApi in providing data, is more lightweight than the MVC architecture.

  

Second documentation:

1 .WebApi 
WebAPI have their own routes. 

webservice and soap wcf protocols are protocols, serialization and deserialization of data format is soap. The webapi is Json data transfer 

advantages webapi of what? 

( 1 ) is suitable for the http request, and a front end interacting webapi particularly convenient 

( 2 ) is lighter because json webapi used to pass data. 

( . 3 ) webapi often provide data to the head end, because webapi with less closely associated with the controller (if not webapi,, then the corresponding control page from a direct mode mvc 
obtain data system device), so that the data transfer webapi Yes, mobile phones, app, pages can provide data through the same data source, it would be more flexible. (Will cross-domain) 

2 .mvc and WebApi: 
difference: 
a.MVC is to establish a framework for the site, tend to return to the user's page request; webApi tend to return user data requests 
b.mvc direct successor system.mvc.controller; webapi inherited system.web.http.ApiController 
c.mvc only be deployed on IIS; webapi may be hosted on different hosts, such as: Web host, Self host mode 
d received parameter is not the same.
e.mvc may return a JsonResult, the front end can be directly used; webapi json to return data must JSON.parse () Conversion (Maticsoft.Json.dll) 
f.webapi webapi controller must be added, changed and inheritance ApiController, otherwise it is invalid the webapi

 

The difference WebApi and MVC

 
Use the distinction, mainly for mvc station, web api is mainly used to build http service, of course, you have to use to build mvc Uri-style Api also, but apparently this is not necessary, an appropriate analogy is like you can also play the cracked version of the stand-alone game, it can also be online through the platform, but still not as good as the steam is more cool is not it.

On its own to achieve distinction, then, is to transform the two frameworks mainly on the basis of the Asp .Net, mainly on HttpModule and HttpHandler to do the expansion, implementation is not the same as, for example, built in the former is more like a layer the second layer, more powerful corollary routing mechanism, such as MvcHandler and ControllerFactory this message processing method and the background controller selection mechanism, Web Api addition extends beyond the former, additionally write a set of separate, independent Asp .Net message processing pipeline , like the reference model of the original house, another set of redesigned villa. This might explain why Web of Api can be hosted on different host (host essence is to use a specific application to provide a running environment for the Web of Api, resolution request and response and the response received) , such as Web Host, Self Host mode, which is similar and WCF. The MVC can only be hosted on IIS (not considering .net core), like a boarding Webform way. Moreover, although both of them have the Controller and Action, but the reply and response mechanisms to achieve the request is different, such as Web Api process the message has two core classes are HttpRequestMessage and HttpResponseMessage. Both frameworks can only say that is the most similar to the model, there are still great differences on implementation. However, the composition of the members of both Asp .Net, showing clearly on the map.
 
First, different issues mainly addressed both!
MVC's main usage scenario is to develop a Web site, he achieved a complete back-end MVC development framework, developers can provide a convenient page, use the default Razor view engine that provides back-end html structure, users can easily develop a site with a page.
The WebAPI starring provides a RestfulAPI development framework, providing a more complete http semantic support, mainly used for open API, more abstract, less emphasis on the View generated.
From an implementation standpoint, although They bundled together, but both the processing line is different.
If you have a more in-depth understanding of the http post, you will find, in fact, is not so obvious They boundaries, you might think mvc do webAPI can do, because he is more abstract, sometimes you do not want two who made so clear boundaries
 
 
 
<<  Previous:  ASP MVC @ Html.CheckBox ( "SEL", to true) back stage pass value problem 
Use the distinction, mainly for mvc station, web api is mainly used to build http service, of course, you have to use to build mvc Uri-style Api also, but apparently this is not necessary, an appropriate analogy is like you can also play the cracked version of the stand-alone game, it can also be online through the platform, but still not as good as the steam is more cool is not it.

On its own to achieve distinction, then, is to transform the two frameworks mainly on the basis of the Asp .Net, mainly on HttpModule and HttpHandler to do the expansion, implementation is not the same as, for example, built in the former is more like a layer the second layer, more powerful corollary routing mechanism, such as MvcHandler and ControllerFactory this message processing method and the background controller selection mechanism, Web Api addition extends beyond the former, additionally write a set of separate, independent Asp .Net message processing pipeline , like the reference model of the original house, another set of redesigned villa. This might explain why Web of Api can be hosted on different host (host essence is to use a specific application to provide a running environment for the Web of Api, resolution request and response and the response received) , such as Web Host, Self Host mode, which is similar and WCF. The MVC can only be hosted on IIS (not considering .net core), like a boarding Webform way. Moreover, although both of them have the Controller and Action, but the reply and response mechanisms to achieve the request is different, such as Web Api process the message has two core classes are HttpRequestMessage and HttpResponseMessage. Both frameworks can only say that is the most similar to the model, there are still great differences on implementation. However, the composition of the members of both Asp .Net, showing clearly on the map.
 
First, different issues mainly addressed both!
MVC's main usage scenario is to develop a Web site, he achieved a complete back-end MVC development framework, developers can provide a convenient page, use the default Razor view engine that provides back-end html structure, users can easily develop a site with a page.
The WebAPI starring provides a RestfulAPI development framework, providing a more complete http semantic support, mainly used for open API, more abstract, less emphasis on the View generated.
From an implementation standpoint, although They bundled together, but both the processing line is different.
If you have a more in-depth understanding of the http post, you will find, in fact, is not so obvious They boundaries, you might think mvc do webAPI can do, because he is more abstract, sometimes you do not want two who made so clear boundaries

Guess you like

Origin www.cnblogs.com/jinanxiaolaohu/p/11467015.html