Ted
Ted

Reputation: 20184

ServiceStack JsonServiceClient: SendAsync uses wrong path, ignores Route attribute?

I am using JsonServiceClient in a Xamarin app, like this:

JsonServiceClient client = new JsonServiceClient("https://my.domain.com/");
SetHeaders(client);

var request = ...; // this is IRequest<T>
var result = await client.SendAsync(request); // <-- FAILS, can't find service

My backend returns an answer, saying that there is no service at that endpoint, which is true, the path that was actually sent over the wire is incorrect.

The request is defined in a lib, like so:

[Route("/mybasepath/endpoint", "POST")]
public class Login : IReturn<LoginResponse>
{
}

The problem is the path that is used in the call, which is wrong and does not follow the Route attribute:

https://my.domain.com/json/reply/Login

Here, ServiceStack client uses the default /json/reply path, even though I have the Route attribute defined in the DTO.

If I change the method used on the client instance, and instead use PostAsync, the path is ten correct and the call work as expected:

JsonServiceClient client = new JsonServiceClient("https://my.domain.com/");
SetHeaders(client);

var request = ...; // this is IRequest<T>
var result = await client.PostAsync(request); // <-- WORKS!

I don't have a minimal project right now that can be immediately tested, maybe it is something easy I have missed?

(Using ServiceStack.Client v 5.10.4 on VS 2019 16.9)

Upvotes: 1

Views: 133

Answers (1)

mythz
mythz

Reputation: 143319

If you want to use ServiceStack's generic Send* APIs the Service Clients needs to explicitly infer the Verb to use by annotating the Request DTO with an HTTP Verb Interface Marker, not necessary for AutoQuery or AutoQuery CRUD APIs which is inferred from their base classes.

Otherwise Send* APIs are designed to fallback to use ServiceStack's pre-defined Routes.

Upvotes: 1

Related Questions