Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jan 09, 2013 10:40 AM by tonybater
Jan 09, 2013 10:40 AM|LINK
In a simple WebApi project, I want to make calls to either return an individual score by score id (int), or all scores for a particular patient (by patient name = string).
I have two routes configured:
and my controller has two methods:
// GET api/Scores/GetScores/patientname
public IEnumerable<Score> GetScores(string pat_id)
return db.Scores.Where(model => model.PatientID==pat_id).AsEnumerable();
public Score GetScore(int id)
Score score = db.Scores.Find(id);
if (score == null)
throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound));
If I have RouteDebugger enabled, then a URL of 'http://localhost:64789/api/Scores/GetScore/8' shows a match to the second route an ID of 8, and a URL of 'http://localhost:64789/api/Scores/GetScores/johnsmith' matches the first route with an id of johmsmith.
If I disable RouteDebugger, both URLs fails with an error like "No HTTP resource was found that matches the request URI 'http://localhost:64789/api/Scores/GetScore/8'.","MessageDetail":"No route providing a controller name was found to match request URI
I can comment out the GetScores(string pat_id) controller method, in which case the URL 'http://localhost:64789/api/Scores/GetScore/8' works, and returns the expected result. However, the reverse case, commenting out the GetScore(int id) method does NOT
work, and the URL 'http://localhost:64789/api/Scores/GetScores/johnsmith still returns the same error - "No HTTP resource was found that matches the request URI 'http://localhost:64789/api/Scores/GetScores/johnsmith.","MessageDetail":"No route providing a
controller name was found to match request URI 'http://localhost:64789/api/Scores/GetScores/johnsmith"}
I have seen threads discussing problems with multiple Get methods, etc., but in this case, even with only one method enabled, I can't get the method with the string parameter to be recognised. Does anyone have any suggestions?