WebAPI not found

I am getting all the WebAPI projects with my limited experience but learning as I go.

I have been given a project in which the want a model with multiple functions
and one(1) controller.  I've setup the models and now want to test each function.
I have set up the controller with the one function and modified App_Start as seen below.
The error messages I'm getting are:
"No HTTP resource was found that matches the request URI
"Message": "No HTTP resource was found that matches the request URI 'http://localhost:62587/api/LobTotals/5'.",
 
"MessageDetail": "No type was found that matches the controller named 'LobTotals'."
api/LobTotals/delete_request/{id}

I've tried multiple variations but powermon cannot find URI



Controller

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

namespace lob_totals.Controllers
{
    public class LobTotalsController : ApiController
    {
        // Delete LOB
        [Route("api/LobTotals/delete_request/{id}")]
        [HttpDelete]
        public IHttpActionResult LobTotals(int id)
        {
           try
           {
               var delete_request = new LobTotals();
               delete_request.delete_request(id);
               return Ok();

           }
         catch (Exception ex)
             {
               return InternalServerError(ex);
             }


        }
        //
    }
}

Open in new window



Model

namespace lob_totals.Models
{
    public class LobTotals
    {
        public int Order_By { get; set; }
        public int Order_by { get; set; }
        public string Lob { get; set; }
        public string lob_num { get; set; }
        public string Total_Date { get; set; }
        public int Total_Num { get; set; }
        public bool Current_Flag { get; set; }
        public string Lob_num { get; set; }
        public int requestor_id { get; set; }
        public int intReturn = 0;
        public string lblTotal = "";
        public bool Convert_Flag { get; set; }
        public int request_num { get; set; }


        public void delete_request(int requestor_id)
        {

            using (var con = lob_totals.Models.Database.GetConnection())
            {
                // Delete LOB Totals
                using (SqlCommand command = new SqlCommand("lobtotals_delete_lob", con))
                {
                    command.CommandType = System.Data.CommandType.StoredProcedure;
                    // execute stored procedure
                    con.Open();
                    //SqlDataReader rdr = command.ExecuteReader();
                    command.Parameters.Add(new SqlParameter("@requestor_id", System.Data.SqlDbType.Int)).Value = requestor_id;
                    using (SqlDataReader rdr = command.ExecuteReader())
                    // Locate row to delete
                    //if (rdr.HasRows)
                    {

                        intReturn = 0;
                        con.Close();

                    }

                    return;
                }
            }
        }
        // Get Lobs Total
        public int Load_Gridview2(int lblTotal)
        {
            using (var con = lob_totals.Models.Database.GetConnection())
            {
                // Get LOB Totals
                using (SqlCommand command = new SqlCommand("lobtotals_get_total", con))
                {
                    command.CommandType = System.Data.CommandType.StoredProcedure;
                    // execute stored procedure
                    con.Open();
                    //SqlDataReader rdr = command.ExecuteReader();
                    command.Parameters.Add(new SqlParameter("@TotalCount", System.Data.SqlDbType.Int)).Value = lblTotal;
                    using (SqlDataReader rdr = command.ExecuteReader())
                        // Locate row to delete
                        if (rdr.HasRows)
                        {

                            intReturn = 0;
                            con.Close();

                        }

                    return lblTotal;
                }
            }
        }
        // Insert Lob
        public string insert_lob(string Lob, int Total_num, string lob_num)
        {
            using (var con = lob_totals.Models.Database.GetConnection())
            {
                // Insert New Lob
                using (SqlCommand command = new SqlCommand("lobtotals_insert_new_lob", con))
                {
                    command.CommandType = System.Data.CommandType.StoredProcedure;
                    // execute stored procedure
                    con.Open();
                    //SqlDataReader rdr = command.ExecuteReader();
                    command.Parameters.Add(new SqlParameter("@lob", System.Data.SqlDbType.Int)).Value = Lob;
                    command.Parameters.Add(new SqlParameter("@Total_Num", System.Data.SqlDbType.Int)).Value = Total_Num;
                    command.Parameters.Add(new SqlParameter("@lob_num", System.Data.SqlDbType.Int)).Value = lob_num;
                    using (SqlDataReader rdr = command.ExecuteReader())
                    // Locate row to delete
                    // 
                    {

                        intReturn = 0;
                        con.Close();

                    }

                    return intReturn.ToString();
                }

            }

        }
        // Load App gridview
        public void Load_Gridview()
        {

            using (var con = lob_totals.Models.Database.GetConnection())
            {
                // Lob Select Request
                using (SqlCommand command = new SqlCommand("lobtotals_select_request", con))
                {
                    command.CommandType = System.Data.CommandType.StoredProcedure;
                    // LOB Select Request
                    con.Open();

                    using (SqlDataReader rdr = command.ExecuteReader())
                        
                        if (rdr.HasRows)
                        {

                            intReturn = 0;
                            con.Close();

                        }

                    return;
                }
            }
        }
        // List Lobs
        public List<LobTotals> GetLobs(List<LobTotals> lobIn, int request_num)
        {

            List<LobTotals> lobs = new List<LobTotals>();

            using (var con = lob_totals.Models.Database.GetConnection())
            {
                using (SqlCommand command = new SqlCommand("lobtotals_select_request_detail", con))
                {
                    command.CommandType = System.Data.CommandType.StoredProcedure;
                    {
                        // execute stored procedure
                        con.Open();
                        command.Parameters.Add(new SqlParameter("@request_num", System.Data.SqlDbType.Int)).Value = request_num;
                        using (SqlDataReader rdr = command.ExecuteReader())
                            // check for rows
                            if (rdr.HasRows)
                                while (rdr.Read())
                                {

                                    LobTotals lob = new LobTotals();

                                    lob.Order_By = Convert.ToInt32(rdr["Order_By"]);
                                    lob.Lob = rdr["Lob"].ToString();
                                    lob.Total_Date = rdr["Total_Date"].ToString();
                                    lob.Total_Num = Convert.ToInt32(rdr["Total_Num"]);
                                    lob.Convert_Flag = Convert.ToBoolean(rdr["Total_Num"]);
                                    lob.Lob_num = rdr["Lob_num"].ToString();

                                    lobIn.Add(lob);

                                }

                        return lobIn;
                    }
                }
            }
        }
        // Update Lob Totals
        public int Total_Update(int Order_By, int Total_Num)
        {
            using (var con = lob_totals.Models.Database.GetConnection())
            {
                // Update LOB Totals
                using (SqlCommand command = new SqlCommand("lobtotals_total_update", con))
                {
                    command.CommandType = System.Data.CommandType.StoredProcedure;
                    // execute stored procedure
                    con.Open();
                    //SqlDataReader rdr = command.ExecuteReader();
                    command.Parameters.Add(new SqlParameter("@Order_By", System.Data.SqlDbType.Int)).Value = Order_By;
                    command.Parameters.Add(new SqlParameter("@Total_Num", System.Data.SqlDbType.Int)).Value = Total_Num;
                    using (SqlDataReader rdr = command.ExecuteReader())
                    // Locate row to delete
                    //if (rdr.HasRows)
                    {

                        intReturn = 0;
                        con.Close();

                    }

                    return intReturn;
                }
            }
        }
        // Lob Totals Update
        public int Totals_Update(int Order_By, int Total_Num)
        {
            using (var con = lob_totals.Models.Database.GetConnection())
            {
                // Update LOB Totals Update
                using (SqlCommand command = new SqlCommand("lobtotals_update", con))
                {
                    command.CommandType = System.Data.CommandType.StoredProcedure;
                    // execute stored procedure
                    con.Open();
                    //SqlDataReader rdr = command.ExecuteReader();
                    command.Parameters.Add(new SqlParameter("@Order_By", System.Data.SqlDbType.Int)).Value = Order_By;
                    command.Parameters.Add(new SqlParameter("@Lob", System.Data.SqlDbType.Int)).Value = Lob;
                    command.Parameters.Add(new SqlParameter("@Lob_num", System.Data.SqlDbType.Int)).Value = Lob_num;
                    using (SqlDataReader rdr = command.ExecuteReader())
                    // Locate row to delete
                    //if (rdr.HasRows)
                    {

                        intReturn = 0;
                        con.Close();

                    }

                    return intReturn;
                }

            }
        }
    }
}

Open in new window



app_Start

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Http;

namespace lob_totals
{
    public static class WebApiConfig
    {
        public static void Register(HttpConfiguration config)
        {
            // Web API configuration and services

            // Web API routes
            config.MapHttpAttributeRoutes();

            config.Routes.MapHttpRoute(
                name: "DefaultApiWithActionId",
                routeTemplate: "api/{controller}/{action}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );
        }
    }
}   

Open in new window



Can someone straighten me out?

Thank you in advance,
Isaac
TechIsaacIT Contracting Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chinmay PatelChief Technology NinjaCommented:
Hi Isaac,

Please spend 30-40 minutes to understand "How"  Web API really works. Do not follow the code as these videos are 6 years old, just the logic part of doing things in true HTTP way. After that, fire any queries you have and I will be more than happy to clarify it.

If you are already aware of how Web API works, just look at the route you have defined in your controller
 [Route("api/LobTotals/delete_request/{id}")]

Open in new window


PS: Please use CODE tags so that your code becomes easily readable.

Regards,
Chinmay.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Chinmay PatelChief Technology NinjaCommented:
Super Thanks Bill :)
Fernando SotoRetiredCommented:
@Chinmay in your first post you state, "these videos", do you have links to them?
Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

Chinmay PatelChief Technology NinjaCommented:
Yikes. I somehow missed posting this link: https://docs.microsoft.com/en-us/aspnet/web-api/videos/getting-started/

Thanks Fernando 🙂
Fernando SotoRetiredCommented:
@Chinmay. 👍
TechIsaacIT Contracting Author Commented:
Thanks for your help.

Much appreciated.

Isaac
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
webapi

From novice to tech pro — start learning today.