我已經完成了這個簡短的測試代碼。但是,它忽略了所有其它的途徑,只打了第一條路線:ServiceStack多個路由路徑
http://localhost:55109/api/customers
工作好
http://localhost:55109/api/customers/page/1
將無法正常工作
http://localhost:55109/api/customers/page/1/size/20
將無法正常工作
當我打電話與頁面的路徑& size params它說:"Handler for Request not found".
我不明白我做錯了什麼?請給我一個提示?
[Route("/api/customers", "GET")] //works okay
[Route("/api/customers/page/{Page}", "GET")] //doesn't work
[Route("/api/customers/page/{Page}/size/{PageSize}", "GET")] //doesn't work
public class Customers {
public Customers() { Page = 1; PageSize = 20; } //by default 1st page 20 records
public int Page { get; set; }
public int PageSize { get; set; }
}
//----------------------------------------------------
public class CustomersService : Service {
public ICustomersManager CustomersManager { get; set; }
public dynamic Get(Customers req) {
return new { Customers = CustomersManager.GetCustomers(req) };
}
}
//----------------------------------------------------
public interface ICustomersManager : IBaseManager {
IList<Customer> GetCustomers(Customers req);
}
public class CustomersManager : BaseManager, ICustomersManager {
public IList<Customer> GetCustomers(Customers req) {
if (req.Page < 1) ThrowHttpError(HttpStatusCode.BadRequest, "Bad page number");
if (req.PageSize < 1) ThrowHttpError(HttpStatusCode.BadRequest, "Bad page size number");
var customers = Db.Select<Customer>().Skip((req.Page - 1) * req.PageSize).Take(req.PageSize).ToList();
if (customers.Count <= 0) ThrowHttpError(HttpStatusCode.NotFound, "Data not found");
return customers;
}
}
我做了兩個「
Tom
2013-03-07 22:19:51