Retour au format xml ou json de MVC, web api basées sur demande

Le suivant webapiconfig;

config.Routes.MapHttpRoute(
            name: "DefaultApi",
            routeTemplate: "api/{controller}/{id}",
            defaults: new { id = RouteParameter.Optional }
        );

et ce contrôleur

  public class ProductsController : ApiController
    {
         Product[] _products = new Product[] 
        { 
            new Product { Id = 1, Name = "Tomato Soup", Category = "Groceries", Price = 1 }, 
            new Product { Id = 2, Name = "Yo-yo", Category = "Toys", Price = 3.75M }, 
            new Product { Id = 3, Name = "Hammer", Category = "Hardware", Price = 16.99M } 
        };

        public IEnumerable<Product> GetAllProducts()
        {
            return _products;
        }
    }

À l'aide de l'URL http://localhost/api/Products je obtenir une liste des produits au format XML.

Ce que j'aimerais, c'est avoir la possibilité de retourner format json ou xml basé sur la demande. Donc, pour json, il serait;

http://localhost/api/Products.json

et pour XML, il serait;

http://localhost/api/Products.xml

de même;

http://localhost/api/Products.json/1/
http://localhost/api/Products.xml/1/

Est-ce possible et comment puis-je obtenir cette fonctionnalité?

Une alternative serait quelque chose comme;

http://localhost/api/json/Products/
InformationsquelleAutor ChrisBint | 2012-10-24