This article is a mirror article of machine translation, please click here to jump to the original article.

View: 30049|Reply: 1

[WebAPI] Use OWIN to serve as a WebAPI host

[Copy link]
Posted on 1/10/2017 2:24:24 PM | | | |
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







Previous:The IAppBuilder interface does not have a UseWebApi method
Next:Due to a page file configuration issue when starting your computer, Windows creates a temporary one on your computer
 Landlord| Posted on 1/10/2017 2:24:55 PM |
The IAppBuilder interface does not have a UseWebApi method
http://www.itsvse.com/thread-3453-1-1.html
(Source: Architect)
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com