Pretty URIs in WCF Data Services – Lose the .svc File
I’m still testing this, but, it looks like in .NET 4 you will be able to use the new URL Routing to lose the .svc file in your WCF Data Services.
Step-by-step
Follow the standard steps for creating a WCF Data Service.
- Create a new, “Empty ASP.NET Web Application”
- Add an Entity Data Model
Once you have your entity data model, add a new class, derive it from DataService<T> where T is the entity set you created in the previous steps:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Data.Services; using System.Data.Services.Common; namespace ODataSample { public class ProductService : DataService<AdventureWorksLT2008Entities> { public static void InitializeService(DataServiceConfiguration config) { config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2; config.SetEntitySetAccessRule("Products", EntitySetRights.AllRead); config.SetEntitySetPageSize("Products", 20); } } }
Add a Global Application Class (global.asax). In the Application_Start method add the following snippet:
RouteTable.Routes.Add(new ServiceRoute("ProductCatalog", new WebServiceHostFactory(), typeof(ProductService)));
If all is well you should be able to hit F5 to debug. Since there is not a default page you’ll have to add the route name you specified onto the end of the URI. If all goes well you should see:
In my testing thus far it appears everything works as you’d expect in terms of appending on query parameters, etc.
Comments are closed.

