In my previous post, I explained how to create a ADO.NET Data Service with Visual Studio 2010. In this post, I will explain how to request this Data Service using Internet Explorer (but this will also work in any other browser). The database used in previous post is AdventureWorks.
By default when accessing the service, the list of all entities is returned.
http://localhost:34570/AdventureWorksService.svc
http://localhost:34570/AdventureWorksService.svc/Products This request lists all products existing in the database.
Let’s go further, you would like to return articles 6 to 7 order by ProductNumber:
http://localhost:34570/AdventureWorksService.svc/Products?$orderby=ProductNumber&$skip=5&$top=2
You could also order the results by ProductNumber descending:
http://localhost:34570/AdventureWorksService.svc/Products?$orderby=ProductNumber%20desc&$skip=5&$top=2
Here is the syntax to filter a product in particular:
http://localhost:34570/AdventureWorksService.svc/Products?$filter=ProductID%20eq%201
http://localhost:34570/AdventureWorksService.svc/Products?$filter=ProductID%20ge%20900%20and%20ProductID%20lt%20950
Other expression syntaxes are available here.
One of the great feature of Data Services is the ability to also return referenced entites.
For example, if you want to request a specific Product, and also return the information defined in its ProductSubCategory property, the request is as follows:
http://localhost:34570/AdventureWorksService.svc/Products?$filter=ProductID%20eq%20771&$expand=ProductSubcategory
And if you also need to retrieve the Catagory entity, which is two levels above :
http://localhost:34570/AdventureWorksService.svc/Products?$filter=ProductID%20eq%20771&$expand=ProductSubcategory,ProductSubcategory/ProductCategory
When your Data Service project is running with debugger inside VS2010, all the requests executed are listed into Visual Studio. Really great feature :-)