ServiceStack异常:尝试将条目插入Sqlite db时,“找不到请求处理程序”

时间:2013-02-26 21:01:04

标签: .net web-services servicestack ormlite-servicestack

我只是在学习如何使用ServiceStack而且我得到一个我无法通过的异常,并且不确定导致异常的原因。这是:

Handler for Request not found:    

Request.ApplicationPath: /
Request.CurrentExecutionFilePath: /entry/5/11-11-2012
Request.FilePath: /entry/5/11-11-2012
Request.HttpMethod: GET
Request.MapPath('~'): C:\Projects\Tutorials\FirstServiceStackApp\FirstServiceStackApp\
Request.Path: /entry/5/11-11-2012
Request.PathInfo: 
Request.ResolvedPathInfo: /entry/5/11-11-2012
Request.PhysicalPath: C:\Projects\Tutorials\FirstServiceStackApp\FirstServiceStackApp\entry\5\11-11-2012
Request.PhysicalApplicationPath: C:\Projects\Tutorials\FirstServiceStackApp\FirstServiceStackApp\
Request.QueryString: 
Request.RawUrl: /entry/5/11-11-2012
Request.Url.AbsoluteUri: http://localhost:52920/entry/5/11-11-2012
Request.Url.AbsolutePath: /entry/5/11-11-2012
Request.Url.Fragment: 
Request.Url.Host: localhost
Request.Url.LocalPath: /entry/5/11-11-2012
Request.Url.Port: 52920
Request.Url.Query: 
Request.Url.Scheme: http
Request.Url.Segments: System.String[]
App.IsIntegratedPipeline: True
App.WebHostPhysicalPath: C:\Projects\Tutorials\FirstServiceStackApp\FirstServiceStackApp
App.WebHostRootFileNames: [entry.cs,entryservice.cs,firstservicestackapp.csproj,firstservicestackapp.csproj.user,global.asax,global.asax.cs,packages.config,recordipfilter.cs,statusquery.cs,statusservice.cs,web.config,web.debug.config,web.release.config,app_data,bin,obj,properties,scripts,x64,x86]
App.DefaultHandler: metadata
App.DebugLastHandlerArgs: GET|/entry/5/11-11-2012|C:\Projects\Tutorials\FirstServiceStackApp\FirstServiceStackApp\entry\5\11-11-2012

我正在通过John Sonmez在ServiceStack上的优秀Pluralsight课程,并刚刚将OrmLite片段添加到我的项目中。当我尝试添加新条目时抛出此异常。所以我的App_Data文件夹中还没有SqlLite文件,也没有创建。当我尝试调试时,它没有破坏代码,因此不确定在哪里寻找...

修改:添加了相关的源代码:

[Route("/entry/{Amount}/{EntryTime}", "POST")]
public class Entry { ... }

public class EntryService : Service 
{ 
    public TrackedDataRepository TDRepository { get; set; } 

    public object Any(Entry request) 
    { 
        var id = TDRepository.AddEntry(request); 
        return new EntryResponse {Id = id}; 
    } 
} 

解决方案:

删除路径定义上的 POST 过滤器,使其适用于所有路线:

[Route("/entry/{Amount}/{EntryTime}")]

1 个答案:

答案 0 :(得分:1)

嗯 - 不确定这是一个OrmLite问题。如果我正确理解了异常消息,则暗示您没有包含正确方法的“服务类**”。在这种情况下,因为HttpMethod是Get你的服务类需要有一个Get(或Any)方法。

您是否有类似下面的“服务类”。

public class EntryService : Service //make sure inheriting from Service or RestServiceBase<Entry> 
{
    public object Get(Entry request)
    {
        //handle request here
    }
}

更新1: 您还需要正确地“路由”您的Entry类。在您的情况下,因为您要添加2个参数(/ 5 / 11-11-2012),您将需要2个路由参数(或带有通配符的参数)。

[Route("/Entry/{P1}/{P2}")] //or use /Entry/{P1*} to use wildcard
public class Entry
{
    public string P1 {get; set;}
    public string P2 {get; set;}
}

**服务类是继承自Service / RestServiceBase的类,它是“处理”您的请求(在本例中为Entry)并返回您的响应(通常遵循{request}响应的名称约定eg.EntryResponse) 。