The full name of OWIN is Open Web Interface for .NET. If we parse only from the name, we can get this information: OWIN is an open web interface for the .NET platform. So who is the interface between the web interface? It is the interface between the web application and the web server, and OWIN is the interface between the .NET web application and the web server. Why do you need such an interface? Because. NET web application runs on a web server, and the .NET web application needs to receive the user's request through the web server and send the response content to the user through the web server. Without such an interface, the .NET web application would depend on the specific web server it was running, for example ASP.NET the application would depend on IIS. With this interface, ASP.NET application only needs to rely on this abstract interface and does not care about the web server it is running. Therefore, the role of OWIN is to decouple by introducing a set of abstract interfaces. NET web application and web server, once again demonstrating the importance of interfaces. In software development, every decoupling is a big step forward. 【Further Understanding】 OWIN is an abstraction of the ASP.NET Runtime. ASP.NET 5.0 is an implementation of OWIN. The following diagrams can be more intuitively understood:
Knowing some basic theory, let's develop it in practice.
OWIN Self-Host ASP.NET Web API 2 First, we create an empty console project:
Then install Microsoft.AspNet.WebApi.OwinSelfHost via Nuget
We can also open the NuGet console: Enter the command: Install-Package Microsoft.AspNet.WebApi.OwinSelfHost
Then we add an OWIN startup class named Startup as follows:
Write code in Startup as follows:
Let's write a WebAPI controller with the following code:
Finally we start OWIN and add the following code in Program.cs:
Launch the console program and access the address we just set:
http://localhost:8080/api/Account
|