2016-04-13 47 views
0

我有一個GET郵件請求,我在Chrome郵差中發出。它看起來像如下:將日期傳遞給WebAPI - 找不到與請求URI相匹配的HTTP資源

http://localhost/WCAPI/Lookup/WCClassDesc/State/AL/Class/7230/DescCode/00/EffDate/2016-04-13

任何人都可以看到,爲什麼我會得到郵差對此有何反應?

{ 
    "Message": "No HTTP resource was found that matches the request URI 'http://localhost/WCAPI/Lookup/WCClassDesc/State/AL/Class/7230/DescCode/00/EffDate/2016-04-13'.", 
    "MessageDetail": "No action was found on the controller 'WCClassDesc' that matches the request." 
} 

我的代碼是:

using System; 
    using System.Web.Http; 
    /// <summary> 
    /// API for loading WCClassDescription which is shown on the PremByClass page. 


    namespace WCAPI.Controllers.Lookup { 

     [RoutePrefix("Lookup/WCClassDesc")] 
     public class WCClassDescController : ApiController { 

      [Route("State/{State}/Class/{Class}/DescCode/{DescCode}/EffDate/{EffDate}")] 
      public Models.Lookup.WCClassDesc Get(string ClassState, string ClassCode, string DescCode, DateTime EffDate) { 

       var desc = (new Premium.BLL.WCClassDesc()).GetCurrentWCClassDesc(ClassState, ClassCode, DescCode, EffDate); 
       var WC = AutoMapper.Mapper.Map<Models.Lookup.WCClassDesc>(desc); 
       return WC; 

      } 
     } 
    } 

任何幫助或方向將不勝感激。

傑森

回答

0

有你的代碼的多個問題,讓我們從URI啓動:

假設你正在測試使用主機(本地主機)的根路徑您的應用程序,並按照您的RoutePrefix定義和Route屬性,正確的URI您的資源如下:

http://localhost/Lookup/WCClassDesc/State/AL/Class/7230/DescCode/00/EffDate/2016-04-13 

這是因爲沒有在你的RoutePrefix ATTRIB定義WCAPI UTE。

的另一個問題是關係到路由參數映射,您已定義參數{State}{Class},但後來你所要求的ClassStateClassCode你的方法裏面。

重命名這些參數以匹配路由中定義的參數,否則Web API將不會將它們映射到您的方法參數。

相關問題