2
votes

everyone!

I've recently tried to use ServiceStack framework and bumped into the following unclearance.

Can I or I can not do the following with that library:

public class userService : Service
{
    public object Get(int? userId)
    {
        // instead of receiving user request object (empty or filled only with its id property)
        return new userResponse();
    }
}

Another thing is weird for me with the whole DTO/Request/Response classes logic, i.e., I should define three classes, which start with similar name ("user" for instance), plus, the service which processes the DTO is found by parameter(!) (Get(user request)). Am I right? Or this is just because I am not fully understand the logic of ServiceStack? If so, then that's pretty inconvenient. That looks pretty weird when Service endpoint (service action) is defined on DTO(!) but not service class initially. Is it possible to do something like this in any way?:

[Route("/users")]
public class userService : Service
{
    public object Get()
    {
        return new ResponseBase(new List<Users>());
    }
    public object Get(int id)
    {
        return new ResponseBase(new User());
    }
}

That looks like mostly a la ASP.NET Web API. However, then a question appears. Why ServiceStack is for? Is it just because it was created earlier?

Thank you!

1

1 Answers

1
votes

You're trying to use ServiceStack like a controller, instead of as the DTO-first message-based services it was designed to support. If you want to use RPC method signatures to create services I recommend going back to using WCF, MVC or WebApi which supports this development model.

If you want to still use ServiceStack, I recommend spending some time to read the Getting Started documentation instead of guessing how it works.

The Simple REST Service on the home page shows exactly how to create a simple service like the one you're trying to create. For further reading on how to design your services see: