문제

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?

도움이 되었습니까?

해결책

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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top