2015-06-12 93 views
1

我有臭名昭着的Web Api沒有找到與控制器名稱匹配的類型。我有這個網絡服務工作,直到我們做了一些文件系統和類的重組,現在我得到這個錯誤。在訪問來自同一解決方案內的類庫的數據類時,文件系統默認使用控制器和模型文件夾。我的路線沒有改變,所以我不認爲這是一個問題。找不到與控制器名稱匹配的類型

這裏是我的控制器:

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; 
     } 

這裏是我的路線:

config.Routes.MapHttpRoute(
     name: "DefaultApi", 
     routeTemplate: "api/{controller}/{id}", 
     defaults: new { id = RouteParameter.Optional } 

,最後,我的錯誤:

{"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'."} 

回答

1

This U RL:

http://localhost:36819/api/getblinks 

要尋找一個叫GetBLinksController控制器,它確實無法找到。我認爲你要做到這一點:

http://localhost:36819/api/meterblinks 

您可能還需要重命名GetBlinks方法簡單Get映射到一個默認的GET請求:

public IEnumerable<JsonMeterBlinksModel> Get(string startDate, string endDate, int meterNumber) 
{ 
    return GetBlinksByDateRange(); 
} 

可以做「命名爲「在WebAPI控制器中的操作,但我懷疑你可能需要爲此添加路由。但默認情況下,它將查找基於動詞的操作(獲取,發佈等)。

0

你的要求應該是/ API/Meter類型鏈接GET

0

那是因爲你寫錯了url。它應該是host and port + "/api/" + controller name + action name。在你的情況將是:

//localhost:36819/api/MeterBlinks/GetBlinksByDateRange 
相關問題