I've got the infamous Web Api No type was found that matches the controller name. I had this web service working until we did a little restructuring of the file system and classes and now I'm getting this error. The File system sits as default with the Controllers and Models Folders while accessing a data class that comes from a class library inside the same solution. My routes haven't changed so I don't think that is an issue.
Here is my controller:
namespace CECC.Services.Controllers
{
public class MeterBlinksController : ApiController
{
// Will return all the meters for the date range with blinks >= minimum blinks passed.
public IEnumerable<JsonMeterBlinksModel> GetBlinks(string startDate, string endDate, int meterNumber)
{
return GetBlinksByDateRange();
}
public IEnumerable<JsonMeterBlinksModel> GetBlinksByDateRange()
{
var conn = new Connection();
List<JsonMeterBlinksModel> blinksCollection = new List<JsonMeterBlinksModel>();
string queryString =
"select meteraccts.meternumber, t1.blinks, scemain.subname, feeder.feedername "
+ "from(select serialnumber, sum(blinkcount) as blinks "
+ "from cecc_processed_blinks "
+ "where trunc(blinkdate) between to_date(:startDate, 'dd-mm-yy') and to_date(:endDate, 'dd-mm-yy') group by serialnumber) t1 "
+ "left join meteraccts on t1.serialnumber = meteraccts.serialnumber "
+ "left join serialnumber on t1.serialnumber = serialnumber.serialnumber "
+ "left join scemain on serialnumber.subid = scemain.subid "
+ "left join feeder on serialnumber.subid = feeder.subid and serialnumber.fdrid = feeder.fdrid "
+ "where METERNUMBER is not null and SUBNAME is not null and FEEDERNAME is not null and t1.blinks >= 0 order by t1.blinks desc";
conn.QueryInto<JsonMeterBlinksModel>(ref blinksCollection, queryString, null);
return blinksCollection;
}
Here is my route:
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
And at last, my error:
{"Message":"No HTTP resource was found that matches the request URI 'http://localhost:36819/api/getblinks'.","MessageDetail":"No type was found that matches the controller named 'getblinks'."}
This URL:
would be looking for a controller called
GetBLinksController
, which indeed can't be found. I think you're looking to do this:You may also need to rename your
GetBlinks
method to simplyGet
to map to a default GET request:You can do "named" operations in a WebAPI controller, though I suspect you may need to add a route for that. But by default it's going to look for verb-based operations (Get, Post, etc.).