Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have api controller in my project which has to retrive data from database based on ISBN

When I am getting an error

":"No HTTP resource was found that matches the request URI 'http://localhost:2280/api/ServiceA/'.","MessageDetail":"No action was found on the controller 'ServiceA' that matches the request."}


What I have tried:

Here is the controller class which have to filter the data based on isbn in the url. but instead its showing no http resource matches the UrI
       [Route("{isbn}")]
       public Book Get(string isbn)
          {

            using (AppDbContext db = new AppDbContext())

            {

                var query = from b in db.Books

                            where b.ISBN == isbn && b.Source == "Book Store 1"

                            select b;

                return query.SingleOrDefault();

            }

        }
    }
}


Here is the table book

public class book
    {
        [Table("Books")]
        public class Book
        {
            public int Id { get; set; }
            public string ISBN { get; set; }
            public string Title { get; set; }
            public string Publisher { get; set; }
            public string Author { get; set; }
            public decimal Price { get; set; }
            public string Source { get; set; }
            public string PurchaseUrl { get; set; }
        }
    }
Posted
Updated 3-Mar-17 18:30pm
Comments
Garth J Lancaster 3-Mar-17 22:15pm    
where does the 'ServiceA' part of this route

'http://localhost:2280/api/ServiceA/'

come from ... I would expect a valid route, given the code you have shown, to be

'http://localhost:2280/api/isbn/'

I'm not saying 'you've got it wrong', I've done a lot with REST but not WEB API 2 .. so the definition/setup may be elsewhere

1 solution

Add a [RoutePrefix("api/ServiceA")] attribute to the controller. Without that, somehow, the valid URI will be http://localhost:2280/isbn instead of http://localhost:2080/api/ServiceA/isbn

C#
[RoutePrefix("api/ServiceA")]
    public class ServiceAController : ApiController

I got the same error without the RoutePrefix attributes
XML
<Error>
  <Message>No HTTP resource was found that matches the request URI 'http://localhost:47503/api/ServiceA/2'.</Message>
  <MessageDetail>No action was found on the controller 'ServiceA' that matches the request.</MessageDetail>
</Error>
 
Share this answer
 
v2
Comments
codegeekalpha 4-Mar-17 14:02pm    
but I dont want a route prefix as api/serviceA. I want my URI to b localhost:2280/api/ServiceA/isbn.. Which is already defined in WebAPI config but with this i am getting error no resource found
Bryian Tan 4-Mar-17 19:00pm    
is the "isbn" word part of the url?
codegeekalpha 4-Mar-17 19:20pm    
Isbn is coming from database and i write it like 1234 which is its value in database and is of string type
Bryian Tan 4-Mar-17 19:46pm    
based on what you presented here, I really don't see why you can not put [RoutePrefix("api/ServiceA")] decorator on top of the controller. Then you can navigate to http://localhost:47503/api/ServiceA/1 to retrieve book where isbn=1 .
Was there an error?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900