简体   繁体   中英

Where does the route /json/syncreply come from in ServiceStack?

I'm trying to send a request to a third party api using this DTO:

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

The client request:

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());

I'm getting a Not Found response currently. When I send to http:// using Fiddler, I can see the path /json/syncreply is added ie ../api/v1/json/syncreply > I am looking to understand where this comes from and how to ensure my request is sent on the right path.

Cheers

The /json/syncreply is route that is defined in ServiceStack API, as a method for sending DTOs without having to provide a specific route for the given DTO, in other words a ServiceStack host would make a route based on the the type name of MyRequest , which can be resolved by ServiceStack clients using the Send method.

3rd party API don't use Send

As you are consuming a 3rd party API using the ServiceStack.JsonServiceClient and their API is not ServiceStack based, then the Send method will not work, because their server API does not have appropriate routes.

The Send method only works for consuming ServiceStack API, because this is a ServiceStack specific feature.

Use the Request DTO

You should be making your request like this, note the Get<T> where T is the request object, MyRequest not MyResponse .

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

And also add a slash at the front of your route declaration on your DTO:

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

tldr;

For 3rd party API that is not a ServiceStack Service, you need to use the appropriate VERB methods such as Get , Post , Put etc, so the route defined on the DTO is used, not the json/syncreply route, therefore simply avoid the Send method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM