Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Web Api and Guids
Message
De
23/06/2014 09:30:12
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
Web Services
Titre:
Web Api and Guids
Versions des environnements
Environment:
C# 4.0
OS:
Windows 8.1
Network:
Windows 2000 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01602225
Message ID:
01602225
Vues:
57
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
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform