[英]re-using ServiceStack DTO in C# client
I've successfully created the Hello World example from the ServiceStack web site and modified it for my needs. 我已经从ServiceStack网站成功创建了Hello World示例,并根据需要对其进行了修改。 Read: Basic authentication, a bit of database access.
阅读:基本身份验证,一些数据库访问。 etc.
等等
I'd like to access the hello service from the test client 我想从测试客户端访问hello服务
[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. 我看到了一些使用“ HelloRespnse”和“ Hello”类型的示例,但是我无法完全弄清楚如何正确导入在服务中创建的DTO。 From the ServiceStack wiki:
从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? 因此,我的问题总结如下:如何在C#客户端中轻松重用在服务中创建的DTO?
Sorry in advance for my lack of totally understanding SS and thanks for the help. 抱歉,我对SS缺乏完全的了解,并感谢您的帮助。
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. 通常的方法是创建一个仅包含DTO模型的单独程序集,并在您的服务实现和客户端中都添加对此程序集的引用。 See Recommended servicestack api structure for more info.
有关更多信息,请参见推荐的servicestack api结构 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.