AlexandreG
AlexandreG

Reputation: 1683

unexpected http get request using JsonServiceClient

I am trying to make a json request on an external service, that would look like this :

GET request :

https://remotehost/path/mycount?foo=C&bar=21

response :

{"count":1000}

for this I use ServiceStack JsonServiceClient, which I like because you can pass a object as parameter. this makes it easy to use/read.

Here is my code :

var client = new JsonServiceClient(classifiedSearchBaseURL);
var response = client.Get<CountResponse>(
                                                       new MyRequest
                                                           {
                                                               foo = "C",
                                                               bar = 21
                                                           });

class MyRequest
{

    public string foo { get; set; }
    public int bar { get; set; }
}

class CountResponse
{
    public string count;
}

But when debugging, instead of getting this http request to the server

GET /path/mycount?foo=C&bar=21

I am getting this

GET /path/json/reply/MyRequest?foo=C&bar=21

Any of you guys has an idea?

Thanks for your help!

Upvotes: 1

Views: 92

Answers (1)

AlexandreG
AlexandreG

Reputation: 1683

The answer is that I should use the Route attribute to the Request object

Following is the modified code

[ServiceStack.Route("/mycount")]
class MyRequest
{
   public string foo { get; set; }
   public int bar { get; set; }
}

Upvotes: 2

Related Questions