2016-04-13 97 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将不会将它们映射到您的方法参数。

相关问题