Reputation: 15861
This is the DTO
public class Employee
{
public int EmployeeID { get; set; }
public string EmployeeName { get; set; }
public string EmployeeeAddress { get; set; }
}
This is the Response
public class EmployeeResponse
{
public List<Employee> listofemp { get; set; }
}
This is the Service stack Service
public class EmployeeServices:Service
{
public dbRepo<Employee> objEmploye; //Repository (which is working fine)
public EmployeeServices()
{
objEmploye = new dbRepo<Employee>();
}
public object getAll(Employee obj)
{
var objlist = new EmployeeResponse {listofemp = objEmploye.GetAll().ToList()};
return objlist.listofemp;
}
}
this is the AppHostBase class
public class ServiceHostApp:AppHostBase
{
public ServiceHostApp()
: base("ServiceStack WebSerivces", typeof(EmployeeServices).Assembly)
{
}
public override void Configure(Funq.Container container)
{
}
}
My Question is why EmployeeServices Metod are not showing in the Metadata ? is there any additional thing do i need to do ??
Upvotes: 1
Views: 1189
Reputation: 1038770
You don't seem to have configured any routes and also haven't respected the naming convention of the service operation.
So you should decorate your request DTO with the Route attribute:
[Route("/employees")]
public class Employee
{
public int EmployeeID { get; set; }
public string EmployeeName { get; set; }
public string EmployeeeAddress { get; set; }
}
and have your service operation be named with the HTTP verb you want it to be accessible with (GET in your case):
public object Get(Employee obj)
{
var objlist = new EmployeeResponse {listofemp = objEmploye.GetAll().ToList()};
return objlist.listofemp;
}
Now when you navigate to GET /employees
the Get operation will be executed.
Bear in mind that you can also configure your routes using the Fluent API
instead of using the Route attribute:
Routes.Add<Employee>("/employees", "GET");
Upvotes: 3
Reputation: 38825
ServiceStack operates on the method names matching the Http Verb used, so instead of getAll
you should really be using Get
(or All
if any verb can be used to do that).
No need to return an object
...
public List<Employee> Get(Employee obj)
{
var objlist = new EmployeeResponse {listofemp = objEmploye.GetAll().ToList()};
return objlist.listofemp;
}
Lastly, you can always adorn Employee
with:
[Route("/Employee")]
public class Employee
{
public int EmployeeID { get; set; }
public string EmployeeName { get; set; }
public string EmployeeeAddress { get; set; }
}
That attribute is define in the namespace ServiceStack.ServiceHost
.
Upvotes: 7