سؤال

I've successfully created the Hello World example from the ServiceStack web site and modified it for my needs. Read: Basic authentication, a bit of database access. etc.

I'd like to access the hello service from the test client

    [Authenticate]
    [Route("/hello/{Name}")]
public class HelloRequest : IReturn<HelloResponse>
{
    public string Name { get; set; }
}

public class HelloResponse
{
    public string Result { get; set; }
}

public class HelloService : Service
{
    public object Any(HelloRequest request)
    {
        var userSession = SessionAs<CustomUserSession>();
        var roles = string.Join(", ", userSession.Roles.ToArray());
        return new HelloResponse { Result = "Hello, " + request.Name + ", your company: " + userSession.CompanyName};
    }
}

I see a few examples out there which appear to be using the "HelloRespnse" and "Hello" types, but I cannot quite figure out how one would properly import the DTO(s) created in the service. From the ServiceStack wiki:

HelloResponse response = client.Get(new Hello { Name = "World!" });
response.Result.Print();

So the summary of my question: How do I easily re-use DTOs created in my service within a C# client?

Sorry in advance for my lack of totally understanding SS and thanks for the help.

هل كانت مفيدة؟

المحلول

The usual way is to create a separate assembly containing just your DTO models, add a reference to this assembly to both your service implementation and client. See Recommended servicestack api structure for more info.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top