Asp.net 向WebAPI传递日期-未找到与请求URI匹配的HTTP资源

Asp.net 向WebAPI传递日期-未找到与请求URI匹配的HTTP资源,asp.net,asp.net-web-api2,Asp.net,Asp.net Web Api2,我在Chrome Postman中有一个GET请求。如下所示: http://localhost/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/

我在Chrome Postman中有一个GET请求。如下所示:

http://localhost/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;

            }
        }
    }
使用系统;
使用System.Web.Http;
/// 
///用于加载在PremByClass页面上显示的WCClassDescription的API。
命名空间WCAPI.Controllers.Lookup{
[RoutePrefix(“查找/WCClassDesc”)]
公共类WCClassDescController:ApiController{
[路由(“State/{State}/Class/{Class}/DescCode/{DescCode}/EffDate/{EffDate}”)]
public Models.Lookup.WCClassDesc Get(字符串类状态、字符串类代码、字符串描述代码、日期时间){
var desc=(new Premium.BLL.WCClassDesc()).GetCurrentWCClassDesc(ClassState、ClassCode、DescCode、EffDate);
var WC=AutoMapper.Mapper.Map(desc);
返回WC;
}
}
}
任何帮助或指导都将不胜感激


Jason

您的代码存在多个问题,让我们从URI开始:

假设您正在使用主机(localhost)的根路径测试应用程序,并遵循
RoutePrefix
Route
属性的定义,那么资源的正确URI如下所示:

http://localhost/Lookup/WCClassDesc/State/AL/Class/7230/DescCode/00/EffDate/2016-04-13
这是因为在
RoutePrefix
属性中没有定义
WCAPI

另一个问题与路由参数映射有关,您将参数定义为
{State}
{Class}
,但随后在方法中要求
ClassState
ClassCode

重命名这些参数以匹配路由中定义的参数,否则Web API将不会将它们映射到方法参数