Use this figure
You can know. API. You can create. Shell. Web MVC and console services in multiple ways.
Procedure for creating an API on the console
1. Create a console
2. nuget install
Static Readonly Uri _ baseaddress = New Uri ( " Http: // localhost: 60064/ " ); Static Void Main ( String [] ARGs) {2. Add default route match Httpselfhostconfiguration Config = New Httpselfhostconfiguration (_ baseaddress); config. routes. maphttproute (Name: " Defaapi API " , Routetemplate: " API/{controller}/{ID} " , Defaults: New {Id = Routeparameter. optional}); 3. Create a server instance VaR Server =New Httpselfhostserver (config); 4. Start the service and listen Server. openasync (). Wait (); console. writeline ( " Web API self hosted on " + _ Baseaddress + " Hit enter to exit... " ); Console. Readline (); server. closeasync (). Wait ();}
Then fiddle requests this address and finds that no content is returned.
Therefore, you need to create a controller: apicontroller inheritance and apicontroller
Write the data that should be returned. OK
Demo