Question

Entering this into the browser:

http://localhost:28642/api/SQLServerPOC/GetByStateOrProvince/California

I get, "No HTTP resource was found that matches the request URI 'http://localhost:28642/api/SQLServerPOC/GetByStateOrProvince/California'."

Yet other REST methods that are very similar work fine. Here's what I mean. Here's the interface:

public interface ISQLServerPOCRepository
{
    int GetCount();
    SQLServerPOC GetByCustomerId(int ID);
    SQLServerPOC GetByFullName(string FName, string MName, string LName);
    IEnumerable<SQLServerPOC> GetByLastName(string LName);
    IEnumerable<SQLServerPOC> GetByCountry(string CountryName);
    IEnumerable<SQLServerPOC> GetByStateOrProvince(string StateOrProvince);
    IEnumerable<SQLServerPOC> GetByPostalCode(string PostalCode);
    IEnumerable<SQLServerPOC> GetAll();
    SQLServerPOC Add(SQLServerPOC item);
}

All of these methods work but two: GetByStateOrProvince() and GetByFullName()

Here is how they appear in the Controller and the Repository (working and non-working shown to reveal there are no fundamental differences):

Controller - the first two work, the last two don't:

[Route("api/SQLServerPOC/GetByLastName/{LName}")]
public IEnumerable<SQLServerPOC> GetSQLServerPOCByLastName(string LName)
{
    return _SQLServerPOCRepository.GetByLastName(LName);
}

[Route("api/SQLServerPOC/GetByZip/{PostalCode}")]
public IEnumerable<SQLServerPOC> GetSQLServerPOCByPostalCode(string PostalCode)
{
    return _SQLServerPOCRepository.GetByPostalCode(PostalCode);
}

[Route("api/SQLServerPOC/GetByFullName/{FName}/{MName}/{LName}")]
public SQLServerPOC GetSQLServerPOCByFullName(string FName, string MName, string LName)
{
    return _SQLServerPOCRepository.GetByFullName(FName, MName, LName);
}

[Route("api/SQLServerPOC/GetByStateOrProvince/{StateOrProvince}")]
public IEnumerable<SQLServerPOC> GetSQLServerPOCByStateOrProvince(string StateOrProv)
{
    return _SQLServerPOCRepository.GetByStateOrProvince(StateOrProv);
}

Repository

public IEnumerable<SQLServerPOC> GetByLastName(string LName)
{
    return customerData.Where(c => c.LastName == LName);
}

public IEnumerable<SQLServerPOC> GetByPostalCode(string PostalCode)
{
    return customerData.Where(c => c.PostalCode == PostalCode);
}

public SQLServerPOC GetByFullName(string FName, string MName, string LName)
{
    return
        customerData.Where(f => f.FirstName == FName)
            .Where(m => m.MiddleName == MName).FirstOrDefault(l => l.LastName == LName);
}

public IEnumerable<SQLServerPOC> GetByStateOrProvince(string StateOrProvince)
{
    return customerData.Where(c => c.StateProvince == StateOrProvince);
}

Note: For "GetByFullName()" I enter:

http://localhost:28642/api/SQLServerPOC/GetByFullName/Catherine/R./Abel     

...but the err from the browser is different, namely:

The resource cannot be found. Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly. Requested URL: /api/SQLServerPOC/GetByFullName/Catherine/R./Abel

Was it helpful?

Solution

First thing I would try would be to rename StateOrProv to StateOrProvince, I have a feeling that those need to match.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top