我使用ServiceStack创建了一个客户服务,但我无法从此方法传递对象列表。
客户服务 -
public class EntityService : Service
{
/// <summary>
/// Request for entity information list
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public object Any(List<CustomerRequest> request)
{
}
}
申请DTO -
[Route("/api/V1/GetCustomerDetails", Verbs = "POST", Notes = "")]
public class CustomerRequest : IReturn<List<CustomerResponse>>
{
[ApiMember(Name = "GetCustomerDetails", Description = "GetCustomerDetails", ParameterType = "body", DataType = "List<BaseRequest>", IsRequired = true)]
List<BaseRequest> _baseRequest {get;set;}
}
public class BaseRequest
{
public string CustId { get; set; }
public string CustName { get; set; }
public string CustAddress { get; set; }
}
您能否告诉我在ServiceStack Post操作中传递对象列表的正确方法。
答案 0 :(得分:4)
ServiceStack中的每个服务都需要接受一个命名的具体请求DTO类型。您可以查看AutoBatched Requests了解如何发送多个请求。
例如,如果您希望服务接受类型列表,您可以继承List<T>
,例如:
public class CustomerRequests : List<CustomerRequest>{}
public class EntityService : Service
{
public object Any(CustomerRequests request)
{
}
}