2016-08-17 84 views
2

我已经使用ServiceStack创建了一个客户服务,但我无法从该方法传递一个对象列表。在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后操作对象的列表中选择正确的方式。

回答

4

ServiceStack中的每个服务都需要接受一个具名的具体请求DTO类型。您可以查看AutoBatched Requests了解如何发送多个请求。

例如,如果你想一个服务接受类型的列表,你可以继承List<T>,如:

public class CustomerRequests : List<CustomerRequest>{} 

public class EntityService : Service 
{ 
    public object Any(CustomerRequests request) 
    { 

    } 
} 
+0

我已经更新了我的问题与BaseRequest class.So可以请证实这是否是正确的执行方式? – Dev

+0

@intelliCoder没有所有的属性应该是公开的,你不应该暴露在你的公共API中以'_'开头的名字,因为拥有'_baseRequest'属性意味着你的服务期望JSON像'{“_baseRequest”:[{“CustId “:1},{”CustId“:2}]}'这很丑陋。 – mythz

+2

@intelliCoder查看ServiceStack文档中的[Designing APIs section](https://github.com/ServiceStack/ServiceStack/wiki#documentation),它介绍了使用ServiceStack创建服务的示例。 – mythz