2

I have created a customer service using ServiceStack but i am not able to pass a list of object from this method.

Customer Service -

public class EntityService : Service
    {
        /// <summary>
        /// Request for entity information list
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public object Any(List<CustomerRequest> request)
        {

        }

}

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; }
}

Could you please let me know what is the correct way to pass list of object in ServiceStack Post operation.

1 Answer 1

4

Each Service in ServiceStack needs to accept a single named concrete Request DTO Type. You can look at the AutoBatched Requests for how to send multiple requests.

E.g, if you want to a Service to accept a List of Types you can inherit List<T>, e.g:

public class CustomerRequests : List<CustomerRequest>{}

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

    }
}
5
  • I have updated my question with a BaseRequest class.So could please confirm if this is the correct way to execute?
    – Dev
    Aug 17, 2016 at 13:23
  • @intelliCoder No all properties should be public and you shouldn't be exposing names starting with _ in your public API as having a _baseRequest property means your Service is expecting JSON like {"_baseRequest":[{"CustId":1},{"CustId":2}]} which is ugly.
    – mythz
    Aug 17, 2016 at 13:28
  • 2
    @intelliCoder have a look at Designing APIs section in the ServiceStack docs, it walks through examples of creating Services with ServiceStack.
    – mythz
    Aug 17, 2016 at 13:32
  • @mythz If I have a third party service sending an array to my API (not wrapped in an object), is there any way to accept that on my end with ServiceStack?
    – JMK
    Aug 7, 2017 at 12:38
  • @JMK ? This answer shows how, have your Request DTO inherit a List.
    – mythz
    Aug 7, 2017 at 12:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.