ServiceStack "Handler for request not found" when it is working for dozens of similar DTOs

StackOverflow https://stackoverflow.com/questions/23601483

  •  20-07-2023
  •  | 
  •  

Вопрос

I have been using ServiceStack for months now. It has been working great for awhile and I've used many advanced approaches and Redis integration. I have a license, so my issue is not regarding a license issue, but I wonder if it is related. It almost looks like I have hit a maximum of DTO or paths, but I do not get any such error, simply the "Handler for request not found". So here is my question: how can you debug and isolate this error? I have read all the posts I can find on proper formats for DTO and DTO filters and I have been doing this long enough that I can see nothing wrong in this regard. Identically styled DTO's and paths work, but new ones fail, or so it seems. Even if I find there is something I am doing wrong in my DTO setup, the question remains, is there a way to debug this? Of course, finding what I'm doing wrong, if that is the case, is the first question.

Here is my code, AppHost first:

.Add<UsersCredentials>("/userscredentials", "GET")
.Add<UserCredential>("/userscredentials", "DELETE")
.Add<UserCredential>("/userscredentials/{UserName}", "POST PUT DELETE")
.Add<UserCredential("/userscredentials/{UserName}/(Permissions}/{System}/{ParamSet}/{Instrument}/{Interval}", "POST PUT DELETE")

DTO:

[Route("/userscredentials", "GET")]
public class UsersCredentials : IReturn<UsersCredentials>
{
    public string UserName { get; set; }
    public string Permissions { get; set; }
    public string System { get; set; }
    public uint ParamSet { get; set; }
    public string Instrument { get; set; }
    public uint Interval { get; set; }
}    //Request DTO

[Route("/userscredentials", "DELETE")]
[Route("/userscredentials/{UserName}", "POST PUT DELETE")]
[Route("/userscredentials/{UserName}/(Permissions}/{System}/{ParamSet}/{Instrument}/{Interval}", "POST PUT DELETE")]
public class UserCredential : IReturn<UserCredential>
{
    public string UserName { get; set; }
    public string Permissions { get; set; }
    public string System { get; set; }
    public uint ParamSet { get; set; }
    public string Instrument { get; set; }
    public uint Interval { get; set; }
}    //Request DTO

And Service:

// UsersCredentials
public class UsersCredentialsResponse
{
    public string Result { get; set; }
    public ResponseStatus ResponseStatus { get; set; } //Where Exceptions get auto-serialized
}

public class UsersCredentialsService : Service
{
    private bool init = false;


    public object Get(UsersCredentials request)
    {

        return (request);
    }

    public object Post(UserCredential request)
    {

        return request;

    }

    public object Put(UserCredential request)
    {

        return request;

    }

    public void Delete(UserCredential request)
    {
    }
}

I use "POSTMAN" for debug and send this as a POST:

    http://sun:1300/userscredentials/a?format=json

It works. Then I send as POST:

    http://sun:1300/userscredentials/a/b/c/1/d/2?format=json

and get, "Handler for Request not found: Request.HttpMethod: POST Request.PathInfo: /userscredentials/a/b/c/1/d/2 Request.QueryString: format=json Request.RawUrl: /userscredentials/a/b/c/1/d/2?format=json"

Это было полезно?

Решение

Routing:

You shouldn't be defining the routes in the AppHost using the .Add<T> method as well as using [Route("/route", "METHOD")] on the DTO.

You only need to use one method. So this may cause conflict, and certainly extra maintenance. I recommend using just the latter, of the Route attribute. So remove the Add rules from your AppHost as they are covered by the DTO routes.

You should also read the routing documentation here, and this post about routing also.

Typo:

You have a typo in your route code. You have an incorrect bracket ( instead of {:

(Permissions}

Should be:

{Permissions}

Metadata

An excellent place to check the service is defined properly is by checking the applications Metadata feature. This is enabled by default, so you can do this by adding /metadata to your server url. i.e.

http://localhost:{port}/metadata

Meta data

You can see an example metadata page here

Hope that helps.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top