ServiceStack picks wrong endpoint when using a Guid in the route

Hi,

First of all thanks alot for such a great framework!

We have two endpoints in the same route, one takes a Guid and the othre takes a long.

When trying to reach the endpoint with a Guid, ServiceStack picks the one with a long and throws the following error:

“The request contained the following invalid parameter errors: ‘A2B2A16A-622A-4620-89CA-5D4008211E7A’ is an Invalid value for ‘Id’”

Endpoint: /domains/info/A2B2A16A-622A-4620-89CA-5D4008211E7A

Our solution is to place a type in the constructor instead, i.e public DomainInfo Get(GetDomainInfoById request) but wondering why it picks the endpoint with the long?

/// <summary>
///     Retrieves a domain
/// </summary>
[Api("Retrieves a domain")]
[Route("/domains/{id}", "GET")]
public class GetDomainById : BaseRequestDto, IReturn<Domain>
{
    [DataMember(Name = "id")]
    public long Id { get; set; }
}
​
/// <summary>
///     Retrieves a domain
/// </summary>
[Api("Retrieves a domain")]
[Route("/domains/{id}", "GET")]
public class GetDomainByGuid : BaseRequestDto, IReturn<Domain>
{
    [DataMember(Name = "id")]
    public Guid Id { get; set; }
}
1 Like

First you need to use the exact property name in your Route, i.e. {Id} instead of {id}.

Your routes are ambiguous here and ServiceStack picks the first match so you’ll need to constrain it to how it matches a rule using a Custom Request Rule, e.g.

[Route("/domains/{Id}", "GET", Matches = "**/{int}")]
public class GetDomainById : BaseRequestDto, IReturn<Domain>
{
    [DataMember(Name = "id")]
    public long Id { get; set; }
}

Note: if this is .NET Core it defaults to camelCase by default, otherwise if you want, you can configure your .NET Framework Service to use camelCase with:

SetConfig(new HostConfig {
    UseCamelCase = true
});

More often than not developers are not using the framework correctly, rather than something being wrong with the framework.

Your suggested solutions work great, thanks!

1 Like