问题
I'm just learning how to use ServiceStack and I am getting an exception that I can't get past and not sure what is causing the exception. Here it is:
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
I'm going through John Sonmez's excellent Pluralsight course on ServiceStack, and have just added the OrmLite piece to my project. This exception is thrown when I attempt to add a new Entry. So I have no SqlLite file yet in my App_Data folder, and none is created. It's not breaking in the code when I try to debug, so not sure where to look for this...
Edit: Added relevant Source Code:
[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};
}
}
Solution:
Remove POST filter on Route definition so it applies to all routes:
[Route("/entry/{Amount}/{EntryTime}")]
回答1:
Hmm - Not sure this is a OrmLite issue. If I understand the exception message correctly it is hinting that you don't have a 'service class**' with the correct method included on it. In this case since the HttpMethod is Get your service class would need to have a Get (or Any) method on it.
Do you have a 'service class' like below.
public class EntryService : Service //make sure inheriting from Service or RestServiceBase<Entry>
{
public object Get(Entry request)
{
//handle request here
}
}
Update 1: You will also need to have your Entry class 'routed' correctly. In your case since your are adding 2 parameters (/5/11-11-2012) you'll need 2 route parameters (or one with a wildcard).
[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 class is your class that inherits from Service/RestServiceBase and it is what 'handles' your request (in this case Entry) and returns your response (generally following the name convention of {request}Response eg.EntryResponse).
来源:https://stackoverflow.com/questions/15099171/servicestack-exception-handler-for-request-not-found-when-trying-to-insert-en