【问题标题】:Where does the route /json/syncreply come from in ServiceStack?ServiceStack 中的路由 /json/syncreply 来自哪里?
【发布时间】:2014-09-29 09:10:32
【问题描述】:

我正在尝试使用此 DTO 向第三方 api 发送请求:

[Route("log_entries", "GET")]
public class MyRequest: IReturn<MyResponse>
{
}

客户端请求:

string uri = "https://..../api/v1"
var jsonClient = new JsonServiceClient(uri);

// This works
var response = client.Get<MyResponse>("/log_entries");

// Does not work
var response = client.Send(new MyRequest());

我目前收到Not Found 回复。当我使用 Fiddler 发送到 http:// 时,我可以看到 添加了路径/json/syncreply,即../api/v1/json/syncreply>我希望了解它的来源以及如何确保我的请求在正确的路径上发送。

干杯

【问题讨论】:

    标签: c# servicestack servicestack-bsd


    【解决方案1】:

    /json/syncreply 是 ServiceStack API 中定义的路由,作为发送 DTO 的方法,无需为给定 DTO 提供特定路由,换句话说,ServiceStack 主机将根据类型名称创建路由MyRequest,可以由 ServiceStack 客户端使用 Send 方法解决。

    第 3 方 API 不使用 Send

    由于您使用第 3 方 API 使用 ServiceStack.JsonServiceClient 并且他们的 API 不是基于 ServiceStack 的,因此 Send 方法将不起作用,因为他们的服务器 API 没有适当的路由。

    Send 方法仅适用于使用 ServiceStack API,因为这是 ServiceStack 的特定功能。

    使用请求 DTO

    您应该这样提出请求,注意Get&lt;T&gt; 其中T 是请求对象,MyRequest 不是MyResponse

    MyResponse response = client.Get<MyRequest>();
    

    并且还在 DTO 的路由声明前面添加一个斜杠:

    [Route("/log_entries", "GET")]
    public class MyRequest: IReturn<MyResponse>
    {
    }
    

    tldr;

    对于不是 ServiceStack 服务的 3rd 方 API,您需要使用适当的 VERB 方法,例如 GetPostPut 等,因此使用 DTO 上定义的路由,而不是 @ 987654337@ 路由,因此只需避免使用Send 方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-11
      • 1970-01-01
      • 1970-01-01
      • 2010-09-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多