1
votes

Hi i am new to servicestack have a problem, with the the routing i have mate a route

[Route("/Person/{ID}", "GET")]
public class GetPersonByID : IReturn<PersonResponse>
{
    public decimal ObjectId { get; set; }
}
[Route("/Organization/{ID}/Person", "GET")]
public class GetPersonByOrganizationId : List<PersonResponse>
{
    public decimal ObjectId { get; set; }
}

but then i am trying /Organization/281478302400588/Persons, I am getting a error saying Unable to bind request

Stacktrace: at ServiceStack.Host.RestHandler.CreateRequest(IRequest httpReq, IRestPath restPath) at ServiceStack.Host.RestHandler.ProcessRequestAsync(IRequest httpReq, IResponse httpRes, String operationName)

1

1 Answers

1
votes
  • You need to ensure that the segment name in the route matches a property in the DTO. So {ID} should be {ObjectId}

  • In the second request, you should be using IReturn<List<PersonResponse>> rather than inheriting from List<PersonResponse> in your request

[Route("/Person/{ObjectId}", "GET")]
public class GetPersonByID : IReturn<PersonResponse>
{
    public decimal ObjectId { get; set; }
}

[Route("/Organization/{ObjectId}/Person", "GET")]
public class GetPersonByOrganizationId : IReturn<List<PersonResponse>>
{
    public decimal ObjectId { get; set; }
}
  • You also note you are trying /Organization/281478302400588/Persons You have used Persons in the request, but the route is Person so either change the request or the route accordingly. (Probably best on the route. i.e. [Route("/Organization/{ObjectId}/Persons", "GET")].

Then ensure in your service you are setting it up similar to this:

public class PersonService : Service
{
    public PersonResponse Get(GetPersonByID request)
    {
        // return new PersonResponse();
    }

    public List<PersonResponse> Get(GetPersonByOrganizationId request)
    {
        // return new List<PersonResponse>();
    }
}

I hope that helps.