Quantcast
Channel: Web API
Viewing all articles
Browse latest Browse all 4850

Why is my Web API REST method not being called?

$
0
0

I created a second "GET" method in my Repository, with two arguments, and yet it is not getting called; the generic method that only takes one argument, and returns all the records, is called. Why? How is the two-arg call being routed to the one-arg call?

Here are the two GET methods in my Repository code:

public IEnumerable<InventoryItem> GetAll()
{
return inventoryItems;
}

public IEnumerable<InventoryItem> Get(string ID, int CountToFetch)
{
IEnumerable<InventoryItem> BatchOfInventoryItems = inventoryItems.Where(i => 0 < String.Compare(i.Id, ID)).Take(CountToFetch);
return BatchOfInventoryItems;
}

I'm calling it with two parameters, a string, and an int, and yet the first one (GetAll()) is the one getting called!

The Controller code looks like this:

public IEnumerable<InventoryItem> GetAllInventoryItems()
{
return inventoryItemsRepository.GetAll();
}

public IEnumerable<InventoryItem> GetBatchOfInventoryItemsByStartingID(string ID, int CountToFetch)
{
return inventoryItemsRepository.Get(ID, CountToFetch); 
}

So when I call "api/Bla/100" from the client, I expect GetBatchOfInventoryItemsByStartingID() in the Controller to get called, calling the Get(ID, CountToFetch) method in the Repository in turn...but it's not happening that way. Why not?


Viewing all articles
Browse latest Browse all 4850

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>