Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Web Api and Guids
Message
From
23/06/2014 09:30:12
 
 
To
All
General information
Forum:
ASP.NET
Category:
Web Services
Title:
Web Api and Guids
Environment versions
Environment:
C# 4.0
OS:
Windows 8.1
Network:
Windows 2000 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01602225
Message ID:
01602225
Views:
58
Hi,

I've got my first Web Api working for data that uses integers as Ids. I'm now struggling to get it to work with a Guid.

I make a call like this:
http://localhost:51673/api/routes/cb877aed-25f1-4a5a-9883-5814a3dec5fd
but it is returning all routes. I set a break point in my controller and it is actually going into this code:
        public IEnumerable<Route> Get()
        {
            return Uow.Routes.GetAll().OrderBy(r => r.rte_name);
        }
not into this code:
        public Route Get(Guid pk)
        {
            var route = Uow.Routes.GetById(pk);
            if (route != null) return route;
            throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound));
        }
My RouteConfig class is this:
    public class RouteConfig
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );
        }
    }
Do I have to make a change here to get it to work with Guids?
Frank.

Frank Cazabon
Samaan Systems Ltd.
www.samaansystems.com
Next
Reply
Map
View

Click here to load this message in the networking platform