ODATA WCF Data Services Friendly URLS using Routing

Posted on

When you creating your first OData WCF Data service common tasks is to give a friendly URL instead of using filename.svc as entry point.You can archive it with URL routing feature in ASP.NET MVC.Just modify your Global.asax.cs route registration block to include following lines.

public static void RegisterRoutes(RouteCollection routes)
       {
           routes.Clear();
           var factory = new DataServiceHostFactory();
           RouteTable.Routes.Add(
               new ServiceRoute("API", factory, typeof (TestOdataService)));

It tells system to associate data service factory handler with a given URL.

Tags: , , , , ,


  • guest

    This doesn’t work because application_start isn’t called when the WCF service is initialized when hosted in IIS (works with the built-in web server in VS)

  • Tweek

    Thanks a lot!