Use the host self host server to create an API Service (if you do not have IIS, you also want to use a rest-style API)

Source: Internet
Author: User

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

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.