2

Closed

Odata route versioning and service document

description

Following the general principle of route based versioning outlined here: http://aspnet.codeplex.com/SourceControl/latest#Samples/WebApi/ODataVersioningSample/ReadMe.txt

I have the following in my v1 namespace:
        var model = modelBuilder.GetEdmModel();
        config.Routes.MapODataRoute(
            routeName: "OData",
            routePrefix: null,
            model: model);

        config.Routes.MapODataRoute(
            routeName: "Version1",
            routePrefix: "v1",
            model: model);
        config.EnableQuerySupport();
I have the following in my v2 namespace:
   var model = modelBuilder.GetEdmModel();

        config.Routes.MapODataRoute(
            routeName: "Version2",
            routePrefix: "v2",
            model: model);

        config.EnableQuerySupport();
Now:
GET "/" == service document
GET "/v1/" == 404, and I expect the service document.
GET "/v2/" == 404, and I expect the service document.
GET "/v1/$metadata"== correct metadata.
GET "/v2/$metadata" == correct metadata.

I can't quite work out what else I'd need to do to get the service document to appear. It's not that important, it's just a quick way of verifying the the service is installed correctly.
Closed Feb 23 at 11:16 AM by jinfutan
It is not reproducible.

comments

raghuramn wrote Nov 7, 2013 at 5:03 PM

you should order your routes appropriately. asp.net routes are matched in the order they are declared. The first route to match wins. When you do a MapODataRoute(prefix), that route takes up all the URL's under that prefix.

So, the order in which you declare routes should be,

config.Routes.MapODataRoute("version1"...
config.Routes.MapODataRoute("version2"...

config.Routes.MapODataRoute(routeName: "OData", ....


Also, I don't really see the need for the last route i.e the one with null prefix. Could you explain why you need that?

AndyIrving wrote Nov 29, 2013 at 3:00 PM

Hi, apologies for the delay in getting back to you.

I'm confident I'm declaring the routes in that order - everything works fine except the service document is unavailable under any prefix (but works with the prefix-less route)
regarding the last route - I want to provide a prefix-less route that provides the V1 behaviour.

cysu wrote Feb 11 at 7:17 AM

Assign to Feng.

fenzhao wrote Feb 19 at 4:53 AM

Can not repro.
May be fixed by other changes.