3

我正在使用 ServiceStack 构建一个相当简单的服务,但是在我的几个服务中出现了这个非描述性错误(在尝试查看 uri 时在浏览器中)。错误代码:请求绑定异常。消息:无法绑定请求。

这是我拥有的 DTO:

[Route("/jtip/cases/{Count}, GET")]
public class AgencyCaseSummary : IReturn<AgencyCaseSummaryResponse>
{
    public int Count { get; set; }
}

public class CaseSummary
{
    public int Id { get; set; }
    public string AgencyCaseNumber { get; set; }
    public string AgencyRepName { get; set; }
    public string Service { get; set; }
    public string Milestone { get; set; }
    public string Status { get; set; }
}

public class AgencyCaseSummaryResponse
{
    public List<CaseSummary> CaseSummary { get; set; }
    public int ActiveCaseCount { get; set; }
    public int OpenRequestCount { get; set; }
}

这是我的服务:

public class AgencyCaseSummaryService : ServiceStack.ServiceInterface.Service
{
    // Injection handled by Funq 
    public IRequestService RequestService { get; set; }
    public ILog Log { get; set; }

    /// <summary>
    /// Gets the case summary for the most recent cases
    /// </summary>
    /// <param name="request"></param>
    /// <returns></returns>
    public AgencyCaseSummaryResponse Get(AgencyCaseSummary request)
    {
        AgencyCaseSummaryResponse summary = new AgencyCaseSummaryResponse();
        Log.Info("Created new agency case summary call");
        try
        {
            if (request.Count > 0)
            {
                var caseSummary = RequestService.GetRecentCases(request.Count);
                summary.ActiveCaseCount = caseSummary.ActiveCaseCount;
                summary.OpenRequestCount = caseSummary.OpenRequestCount;

                if (caseSummary.Cases.Count > 0)
                    summary.CaseSummary = DTOMapper.Map(caseSummary.Cases);
            }
        }
        catch (Exception ex)
        {
            Log.Error("Api.AgencyCaseService", ex);
        }
        return summary;
    }
}

我在这里错过了什么吗?错误是什么意思?

4

1 回答 1

7
[Route("/jtip/cases/{Count}, GET")]
public class AgencyCaseSummary : IReturn<AgencyCaseSummaryResponse>
{
    public int Count { get; set; }
}

route 属性需要 URL 模板和方法作为单独的参数(请参阅RouteAttribute.cs

因此,要解决您的问题,请将属性更改为

[Route("/jtip/cases/{Count}", "GET")]

至于错误是什么意思,当路由匹配但无法转换(或反序列化)URL时,由RestHandler( RestHandler.cs )抛出

于 2013-08-05T18:10:06.343 回答