ServiceStack JsonServiceClient:SendAsync使用了错误的路径,忽略了Route属性



我在Xamarin应用程序中使用JsonServiceClient,如下所示:

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

我的后端返回一个答案,说在该端点上没有服务,这是真的,实际通过连线发送的路径是不正确的。

request在库中定义,如下所示:

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

问题是调用中使用的路径是错误的,并且没有遵循Route属性:

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

这里,ServiceStack客户端使用默认的/json/reply路径,尽管我在DTO中定义了Route属性。

如果我更改在client实例上使用的方法,而改为使用PostAsync,则路径是10正确的,并且调用按预期工作:

JsonServiceClient client = new JsonServiceClient("https://my.domain.com/");
SetHeaders(client);
var request = ...; // this is IRequest<T>
var result = await client.PostAsync(request); // <-- WORKS!

我现在没有一个可以立即测试的最小项目,也许这是我很容易错过的东西?

(在VS 2019 16.9上使用ServiceStack.Client版本5.10.4(

如果要使用ServiceStack的通用Send*API,服务客户端需要通过用HTTP谓词接口标记注释请求DTO来显式推断要使用的谓词,这对于从基类推断的AutoQuery或AutoQuery CRUD API来说是不必要的。

否则,Send*API被设计为回退以使用ServiceStack的预定义路由。

最新更新