Introduction

This article show how to select a specific page and port in the Web API. Here we define the specific port for execution of the application. The application can execute on the defined specific port. Now let's see the example of the application.

Create an Web API Application.
After creating the application open the property window of the Web API project.

Now execute the application. The application will use port "8384".

Get value

Now add a Model class as in the following:
Now in the ValuesController perform some changes:

Add the following code:

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Net;
  5. using System.Net.Http;
  6. using System.Web.Http;
  7. using SelectPortWebAPI.Models;
  8. namespace SelectPortWebAPI.Controllers
  9. {
  10. public class ValuesController : ApiController
  11. {
  12. // GET api/values
  13. public Product Get()
  14. {
  15. return new Product
  16. {
  17. Id = 1,
  18. Name = "Keyboard",
  19. category = "Hardware"
  20. };
  21. }
  22. }
  23. }

Now again execute the application. it uses the port "8384" and the "api/values" page. It can not use the other port.

Get All Value