First, the rules interface

Then we find out: Why use WebAPI?

    Before explaining this question we need to know about .net provides an interface for an external means what?

    A: WCF, WebService , WebAp, general handler.

      Then take a look at the differences between them:

        WebService

            1: soap based protocol, data format is xml,

            2: Only the http protocol,

            3: not open source, but can be any person to use an understanding of xml,

            4: can only be deployed on iis.

        WCF

            1: soap based protocol, data format is xml,

            2: WCF webservice is an evolution, support a variety of protocols, such as TCP, http, https, NamedPipes, MSMQ, etc.

            3: not open source, but can be any person to use an understanding of xml,

            4: can be deployed in an application, the IIS or Windows service.

        WebAPI :

            1: is a simple to build a new framework http services,

            2: In the .net platform WebAPI is an open source, ideal for building RESTful technology services,

            3: You can use all the features of the http, (such as URIs, request / response header, cached, version control, a variety of content formats),

            4: mvc support characteristics, like routing controller, action, fiter, model binding, inversion of control, dependency injection, unit testing,

            5: can be deployed in an application, on IIS,

            6: is a lightweight framework to support a variety of terminals are very good,

            7: Response can be converted webAPI of MediaTypeFormatter into json, XML or any format you want to convert.

        General handler :

            General handler in fact, and page processing program with distinction, because implementation is IhttpHandler interface, and does not need to inherit from the Page class. So there is no need to deal with so many events, do not consume too many resources, so performance than aspx high.

So back to the question, why use WebApi?

        When you meet the following these cases when you can consider using webAPI to build up your service;

            1: webservice needs but does not need soap,

            2: The need to establish a non-soap-based http service on the existing WCF service basis,

            3: just want to post some simple http service, wcf not want to use relatively complex configuration,

            4: Publish the service will be limited to devices to access bandwidth,

            5: I hope to use open-source framework, the key moment can debug your own custom look or frame.

 

To sum up the difference between the WebAPI and MVC: What is the difference between WebAPI and MVC?

        I believe used mvc and webapi students will find both too similar, using them is similar, but since it is two frames, it is certainly a difference, my difference of MVC WebAPI and do a little summary:

            1: MVC is mainly used to build the site, both concerned about the data also show concern page, but WebAPI only interested in data,

            2: WebAPI supported formats negotiation, the client can inform the server through the Accept header format desired,

            3: WebApi support Self Host, MVC is not currently supported,

            4: WebAPI express different actions (CRUD) through different http verb, MVC is expressed through action Action name,

            5: WebAPI built at System.Web.Http namespace, located in the MVC Systm.Web.Mvc namespace, so slightly different routing,

            6: WebAPI very suitable for building mobile client service.

Guess you like

Origin www.cnblogs.com/fger/p/11119345.html