WCF Data Services (OData) and eliminating the .SVC file

After my previous post where I showed you how you can eliminate the .SVC extension from your URI someone asked me another good question.

When I add the route I can access the service from the route and the path to the SVC file.  Can I block the path to the SVC file from accessing the service?

Absolutely – all you have to do is get rid of the .SVC file.  But be careful when you do!  If you delete the .svc file VS2010 will also delete the code-behind file.

 

VS2010 treats the file where your service code lives as code-behind so it offers you a limited set of options for dealing with it.

image

The best thing to do is to open the file and save it without the .svc extension.  In this case I saved it as Conference.cs.

Now you can delete the .SVC file this will prevent it from being used as a path to access the service

 

image

With the .SVC file gone only the URI from the route will be able to access your service.