2

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!

Agat
  • 4,577
  • 2
  • 34
  • 62

1 Answers1

1

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:

Community
  • 1
  • 1
mythz
  • 141,670
  • 29
  • 246
  • 390
  • Thanks for the answer. Actually, I did read the 'Getting Started' documentation and I did see that very cs file sample. And actually it was mostly a reason of asking this question. As the logic looks a kind of weird for me when the system determines which exactly service class to call dependently on call method parameters. And I asked that because since it looks weird for me, that means either I don't get something in the area or... "it-was-implemented-some-time-ago-in-such-way-because-it-was-implemented-in-such-way". So, if so, I've got an answer. :) – Agat Jun 04 '13 at 16:36
  • It's purposely different to support a DTO-first, message-based design. It's [designed to change how you approach web service development](https://github.com/ServiceStack/ServiceStack/wiki/What-is-a-message-based-web-service%3F), i.e. instead of thinking about invoking a remote server method signature, it wants you to instead think about sending a message to a remote instance - decoupling the request from the implementation. – mythz Jun 04 '13 at 16:39