Question

Two of my three Web API methods work fine; the third doesn't - it barks at me, Dobermanesque: "remote server returned an error (404) not found"

Here are the Controller methods:

[Route("api/Subdepartments/GetCount")]
public int GetCountOfSubdepartmentRecords(string serialNum)
{
    return _subdepartmentsRepository.GetCount(serialNum);
}

[Route("api/Subdepartments/GetAll")]
public IEnumerable<Subdepartment> GetAllSubdepartmentRecords(string serialNum)
{
    return _subdepartmentsRepository.GetAll(serialNum);
}

[Route("api/Subdepartments")]
public IEnumerable<Subdepartment> GetBatchFromID(string serialNum, int ID, int CountToFetch)
{
    return _subdepartmentsRepository.GetBatch(ID, CountToFetch, serialNum);
}

Here are the Repository methods:

public int GetCount(string serialNum)
{
    LoadSubdepartments(serialNum);
    return subdepartments.Count;
}

public IEnumerable<Subdepartment> GetAll(string serialNum)
{
    LoadSubdepartments(serialNum);
    return subdepartments;
}

public IEnumerable<Subdepartment> GetBatch(int ID, int CountToFetch, string serialNum)
{
    LoadSubdepartments(serialNum);
    return subdepartments.Where(i => i.Id >= ID).Take(CountToFetch);
}

...and here are the URIs I am passing:

http://localhost:28642/api/Subdepartments/GetCount?serialNum=8675309e9
http://localhost:28642/api/Subdepartments/GetAll?serialNum=8675309e9
http://localhost:28642/api/Subdepartments?serialNum=8675309e9&Int=1&CountToFetch=5

Why do GetCount() and GetAll() work, while GetBatch() does not?

Was it helpful?

Solution

Because you have Int= instead of ID= in your querystring.

So the URI you are passing should be

http://localhost:28642/api/Subdepartments?serialNum=8675309e9&ID=1&CountToFetch=5
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top