ASP.NET Web API takes the advantage of HTML feature to create web apis for exposing services and data on top of .net framework.
Way to access web service SOAP vs REST:
SOAP : SOAP relies exclusively on XML to provide messaging services. Microsoft originally developed SOAP. Old technologies DCOM was binary messaging; the XML messaging that SOAP employs works better over the Internet.
We Don’t see the XML .Complex we have WSDL definition of how the Web service works.
Instead of using XML to make a request, REST relies on a simple URL in many cases.
Both SOAP and REST share similarities over the HTTP protocol.
Introduced with .NET 4.5
WCF is a back end service mean while Web API is more of a front end service.
Initially WCF Web API then goes with ASP .NET MVC 4.
Web API is sometimes considered a synonym for web service, Web 2.0 (Allow users to interact and collaborate with each other ex. social networking sites, blogs etc..).
Web applications have moved away from SOAP-based web services towards more cohesive collections of RESTful web resources. These RESTful web APIs are accessible via standard HTTP methods by a variety of HTTP clients including browsers and mobile devices.
WEB API- HTTP based , NO configuration.
Non- SOAP based services.
“verbs” built into the HTTP protocol (GET, POST, PUT, and DELETE) map directly to application-level operations for receiving, sending, modifying, and deleting data.
Renders raw data not views.
Debugging is also easier, because you can load up the web service in any web browser and see the raw data.
Major Components of ASP.NET Web API:
# Model: Model is an object which keeps the data. ASP.NET Web API automatically serialize the model into different data formats JSON, XML and other formats and write them into the HTTP response.
Model could be a static class with hard coded values or a class generated by ADO.NET Entity Framework.
#Controller: Controller is an object that handles the HTTP request. Inherits ApiController.
In controller we create the object of Model data and then use them in public methods also called as ActionMethods/ Actions
public static TestLocalDBEntities dbContext = new TestLocalDBEntities();
public static IQueryable<Product> prdQuery = dbContext.Products.AsQueryable<Product>();
IEnumerable<Product> products = prdQuery.ToList();
Like above we have the products object which holds the data from Products table using EF.
For selecting template for Web API without MVC.– Select Empty template + Web API check box.