The .NET Endpoint

Blog by the .NET and AppFabric teams about WCF and WF development, deployment, and management

endpoint.tv - Getting Control of the URI with RESTful WCF Services

endpoint.tv - Getting Control of the URI with RESTful WCF Services

  • Comments 2

RESTFul people want to control the URI of their services.  They focus on building a good information architecture that describes the resources their site provides.  Historically most web sites described resources in terms of files and paths in the virtual root of the web server.  But what if your resources are coming from a database and there are no files to speak of?  What is the URI of your service then?

The default behavior of a RESTful web service  in WCF is that you have a SVC file like "MyService.svc" and the first segment of your URI (after the host) is the path to the SVC file on your web site.  The remaining portion of the URI is the name of your method and a query string arguments for the parameters.

For example

http://www.example.com/myservice.svc/GetWine?wineId=17

You can partially control this URI by applying a URI template.  So for example in this case we could attribute the operation contract with a template like this

[WebGet(UriTemplate="wine/{wineId})]

This will change the portion of the URI after the .svc extension so our URI will look like this

http://www.example.com/myservice.svc/wine/17

Nice, but what if you want to eliminate the .svc extension? Well there are several ways you can get this done

My colleague Rob Bagby has created a nice screencast for endpoint.tv with a complete walkthrough of controlling the URI that features

Be sure to check it out and build some RESTful WCF Services with the URI just the way you want it.

Page 1 of 1 (2 items)