Jezz Santos - 8 - Mar 10, 2015

Routing for and image service

I have a service that serves up images as System.IO.Stream.

I have a Get() method that uses this DTO:

[Route(@"/pics/{Size}/{Id}.png", @“GET”)]
    public class GetPngPic
        public string Id { get; set; }

        public string Size { get; set; }

Since I added the ‘.png’ part to the route I am now getting the following types of errors calling this service: 

"None of the given rest routes matches ‘GetPngPic’ request:
/pics/{Size}/{Id}.png: Component ‘{Id}.png’ can not be parsed"

Is there a way to stop getting this error?

Rob Schoenaker:

What does the service itself look like?
Also, which features are enabled in the HostConfig?

I’ve just added a test for this that’s working as expected:

Not sure why it’s not working for you, are you using the latest version?

Jezz Santos:

Thanks demis for setting up the tests.

I am equally confused because as it turns out the exception is not reliable. It actually seems to work fine in use (called from a web site client), I am seeing these errors in integration testing only, where I am throwing various values at the two parameters {Size} and {Id}. such as 0 for the size (which is valid according to our rules), and Id is always a GUID.

Rob, the actual service looks like this:

[AddHeader(ContentType = @“image/png”)]
public Stream Get(GetPngPic body)
// serve image from blob storage as a stream

We have nothing unusual on our config and standard features like Validation, Cors, swaggerui. no request or response filters.

Ill do some more investigation. thanks for the affirmation that this should just work the way it is - that is real good value to me.

Jezz Santos:

+Demis Bellot OK, I took your new tests, and added one of my own to demonstrate the issue.

Turns out that your tests work fine, but when I call the same method using the JsonServiceClient it fails in the way I have explained. Here is the test to repo the problem.

        public void Can_download_route_with_dot_seperator_and_extension_with_jsonserviceclient()
            var client = new JsonServiceClient(Config.AbsoluteBaseUri);
            var response = client.Get(new GetPngPic
                Id = “1”,

            Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));

hmmm, any idea why it would fail using the ServiceClient, but not with the GetJsonFromUrl() extension method??

yeah looks like the reverse routing on the client doesn’t support it, which you can check with:

new GetPngPic {
  Id = “1”,
  Size = “100x100”,

I’ll look into it, in the meantime you can use the Get(“path/info”) API’s in the JsonServiceClient to workaround it.

Jezz Santos:

Are you saying that this should work in the meantime?

            var response = client.Get("/pics/100x100/1.png");

Because right now that gives me: 400 - Bad Request

You’ll need specify the return type, but yeah:

var client = new JsonServiceClient(Config.AbsoluteBaseUri);
var response = client.Get<GetPngPic>("/pics/100x100/1.png");

is working for me.

Jezz Santos:

Damn hate to report this.
Yes I have that code same as you and in  the context of the RouteTests.cs, I am still getting 400 - Bad Request

Do you have the StackTrace? and are using the latest version?

I’ve also added a fix for this:

But I’m still in the middle of a refactor so wont be able to push to MyGet till it’s sorted. Will let you know when next version is deployed to MyGet.

Jezz Santos:

Yes, latest version. my mistake, I had added the header to method:

        public object Any(GetPngPic request)
            return request;

That was giving me the 400 - Bad request.

Now when I remove that in this test with ServiceClient, it works as you said - sorry

FYI latest changes with this fix is now available from v4.0.39 that’s now on MyGet:

Jezz Santos:

Thanks heaps Demis. Will pick up that on our next version rev. Thanks for all this.