locked
how to debug Web API project using .net framework RRS feed

  • Question

  • User-1286535781 posted

    I am new to .net Web API development. I have been provided a solution, not sure from where do I need to start debugging the project. Can someone please advise step by step procedure for me to debug. Thanks 

    Any step by step video links or documents will be great help

    Monday, March 9, 2020 2:51 AM

All replies

  • User-17257777 posted

    Hi reason101,

    You can use VS debugger to debug like other applications. Or you can use some API debugging tools like fiddler and Postman.

    The first thing you have to do is starting your web api application.

    https://www.tutorialsteacher.com/webapi/test-web-api

    Best Regards,

    Jiadong Meng

    Monday, March 9, 2020 6:20 AM
  • User1120430333 posted

    You simply make the WebAPI use IIS Express. You set the WebAPI as the Start project in Visual Stuido. You start the project in debug mode, which brings up the browser where you can enter a URL to a controller. You set a breakpoint in the code. You enter a URL to a controller action method don't for forget the port number the service is listing on. You enter the URL in the browser address line and make the browser use the URL.

    The WebAPI has a sample test controller that VS puts into the project. So if you get that to show it's data as a retrun result in hitting the test controller, the you should be able to hit the other controllers and their action methods.

    https://docs.microsoft.com/en-us/visualstudio/debugger/how-to-enable-debugging-for-aspnet-applications?view=vs-2017

    You can also use Postman (free) too.

    Monday, March 9, 2020 6:24 AM
  • User-1286535781 posted

    Thanks for the link.

    I wanted to use .NET Framework design pattern for building, deploying and debugging Web APIs

    Do you have any video tutorials which can show this in step by step ?

    Monday, March 9, 2020 6:27 AM
  • User-17257777 posted

    Hi reason101,

    You can refer to ASP.NET Web APIs offical document:

    https://docs.microsoft.com/en-us/aspnet/web-api/overview/getting-started-with-aspnet-web-api/tutorial-your-first-web-api

    Best Regards,

    Jiadong Meng

    Monday, March 9, 2020 9:42 AM
  • User1120430333 posted

    Thanks for the link.

    I wanted to use .NET Framework design pattern for building, deploying and debugging Web APIs

    Do you have any video tutorials which can show this in step by step ?

    I learned WebAPI architecture on the job. But I did learn more  when I looked at the blow link and downloaded the code and made it work without involving Azure. But it's not a typical usage of the WebAPI. The WwbAPI uses the MVC pattern 

    https://docs.microsoft.com/en-us/aspnet/web-api/overview/data/using-web-api-with-entity-framework/part-1

    https://www.tutorialspoint.com/asp.net_mvc/asp.net_mvc_web_api.htm

      I eventually graduated to the architecture below by using the DTO pattern it talks about on the above link and implementing SoC by moving the persistence  in the data access layer (DAL) using the DAO pattern in the DAL using EF. The WebAPI is use a conduit that works on the behalf of the client. The real work is in the DAL.

    https://www.codeproject.com/Articles/1050468/Data-Transfer-Object-Design-Pattern-in-Csharp

    https://en.wikipedia.org/wiki/Separation_of_concerns

    https://www.tutorialspoint.com/design_pattern/data_access_object_pattern.htm

    example WebAPI code.....

    using System.Collections.Generic;
    using System.Threading.Tasks;
    using DAL;
    using Entities;
    using Microsoft.AspNetCore.Mvc;
    
    namespace WebApi3.x.Controllers
    {
        [Produces("application/json")]
        [Route("[controller]")]
        [ApiController]
        public class AuthorController : ControllerBase
        {
            private IDaoAuthor dao;
            public AuthorController(IDaoAuthor daoAuthor)
            {
                dao = daoAuthor;
            }
    
            [HttpGet]
            [Route("GetAll")]
            public async Task<List<DtoAuthor>> GetAll()
            {
                return  await dao.GetAll();
            }
    
            [HttpGet]
            [Route("GetAuthorTypes")]
            public async Task<List<DtoAuthorType>> GetAuthorTypes()
            {
                return await dao.GetAuthorTypes();
            }
    
            [HttpGet]
            [Route("Find")]
            public async Task<DtoAuthor> Find(int id)
            {
                return await dao.Find(id);
            }
    
            [HttpPost]
            [Route("Add")]
            public async Task Add(DtoAuthor dto)
            {
                 await dao.Add(dto);
            }
    
            [HttpPost]
            [Route("Update")]
            public async Task Update(DtoAuthor dto)
            {
                await dao.Update(dto);
            }
    
            [HttpPost]
            [Route("Delete")]
            public async Task Delete(DtoId dto)
            {
                await dao.Delete(dto.Id);
            }
        }
    }

    Monday, March 9, 2020 10:15 AM