rudygt
rudygt

Reputation: 75

Exception with default value on route

I had a Dto with the following route defined

        [Route("/route/{Id}/{Status}")]
        public class JustIdAndStatus : IReturn {
            public long Id { get; set; }
            public long Status { get; set; }
        }

Then I invoke the service with something like

localhost:9040/route/1/100

or

localhost:9040/route/0/100

and everything goes well.

but when I use one of the service clients I got an exception if any of the values is 0 (default value for the long).

   var client = new JsonServiceClient("http://127.0.0.1:9040");

   var request = new JustIdAndStatus() {
                    Id = 0,
                    Status = 1
                };

   var response = client.Get(request);

the exception I get is

System.InvalidOperationException : None of the given rest routes matches 'JustIdAndStatus' request:
    /route/{Id}/{Status}:   Could not match following variables: Id
   at ServiceStack.ServiceClient.Web.UrlExtensions.ToUrl(IReturn request, String httpMethod, String formatFallbackToPredefinedRoute) in UrlExtensions.cs: line 65
   at ServiceStack.Common.Tests.UrlExtensionTests.Can_create_url_with_JustIdAndStatus(Int64 id, Int64 status) in UrlExtensionTests.cs: line 91

I tracked down the issue to this commit on the service stack repository https://github.com/ServiceStack/ServiceStack/commit/b34a5906a265da19d916ea47ee80783bd866abcb

I notice that when I updated from ServiceStack 3.9.38 to 3.9.40 from nuget.

I want to know if this behavior is right, so I'm using the routes in a wrong way or maybe this is an issue and can be submited to the issue tracker on github.

also I make a test using the basic ones I found on ServiceStack.Commons source code

https://gist.github.com/anonymous/5216727

Thanks in advance!

Upvotes: 3

Views: 832

Answers (1)

Phil Degenhardt
Phil Degenhardt

Reputation: 7264

I agree with you that what you describe should be expected behaviour where the property is specifically referenced in the route.

The commit you refer to was intended to suppress the use of default parameter values on routes where members were relegated to the query string. However, it also appears to have caused the issue you describe with explicit routes.

I am putting together a pull request to address the issue and add some tests to reflect the expected behaviour.

Upvotes: 3

Related Questions