When testing my web API C# ASP.NET locally on Fiddler it returns an error 404

Asked

Viewed 281 times

0

I am creating a stock control system with integration of android app,the connection is being made through a Web Service API. However I can not test the methods that exist in it to see the returned results,I am using Fiddler but whenever I call the url by it returns me error 404 not found. The programming language used is C# and I am using ASP.NET 4.6.

Thank you so much already. Please if anyone has clues or deeper notion I accept urgent help.

Below are Screenshots of Project Explorer, Fiddler Error as well as some Codes

Controller:

using System;
using APITeste.Models;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;

namespace APITeste.Controllers
{
    public class PessoaController1 : ApiController
    {
        private static List<Models.Pessoa> _pessoas = new List<Models.Pessoa>();
        // GET: api/Pessoa
        public IEnumerable<Models.Pessoa> Get()
        {
            return _pessoas;
        }

        // GET: api/Pessoa/5
        public Models.Pessoa Get(int id)
        {
            return _pessoas.FirstOrDefault(pessoa => pessoa.ID.Equals(id));
        }

        // POST: api/Pessoa
        public void Post([FromBody]Models.Pessoa value)
        {
            _pessoas.Add(value);
        }

        // PUT: api/Pessoa/5
        public void Put(int id, Models.Pessoa value)
        {
            var pessoa = Get(id);
            if (pessoa != null)
            {
                pessoa.Nome = value.Nome;
                pessoa.Sobrenome = value.Sobrenome;
            }
        }

        // DELETE: api/Pessoa/5
        public void Delete(int id)
        {
            var pessoa = Get(id);
            if (pessoa != null)
                _pessoas.Remove(pessoa);
        }
    }
}

Model:

namespace APITeste.Models
{
    public class Pessoa
    {
        public int ID { get; set; }
        public string Nome { get; set; }
        public string Sobrenome { get; set; }
    }
}

Fiddler Debugger:

Fiddler Debugger Screenshot

Solution Explorer:

Solution Explorer Screenshot

  • Tip: Select the code and click Ctrl + K leaves it formatted.

  • Try renaming PessoaController1 for PessoaController

  • Man..... I can hardly believe it, I just had to take out the 1 like you said.... and Fiddler got to read it. I swear to you I’m three days almost sleepless trying to figure this out, thank you so much for your help.

1 answer

1


This happens because the controller person with the name PessoaController1.

The controllers need to have only Controller at the end of the name.

Rename the class PessoaController1 for PessoaController.

Note: Renaming the class, the file is indifferent.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.