I find it helpful to use the browser to visualize immediate cause and effect of queries to an Astoria web data service. THere’s so much more that you can do when you are really using this in applications, though.
In the documentation there’s a list of query operators:
- callback (specific to JSON for AJAX calls)
- expand – pull related data using EDM associations
- format – define format of the response (eg xml, json, rdf)
- keyset- only return the entityKeys
- orderby (you know what this is)
- skip (same as in LINQ)
- top
The doc explains each of these in more detail.
Here for example, I can get a specific customer and all of their sales order headers. (Make sure you have MultipleActiveResultSets=true in your connection string in order to do this. That allows the db to return more than one result on the same connection string .. a feature added in that we first acquired with .NET 2.0 and SS2005.)
I can drill even further to return the SalesOrderDetail data form the SalesOrderHeader using this URI:
http://localhost:55976/WebDataService1.svc/Customer[6]?$expand=SalesOrderHeader.SalesOrderDetail
Here’s an example of using skip
Looking at the non-xml formats is tough in Internet Explorer, at least with JSON as IE doesn’t know how to display the response. There are a few ways around this.
1) (bit of a hack :-))
Add this into the appSettings seciton of web.config
<add key=”EnableAstoriaJSONP” value=”true”/>
and then browse your service in Firefox, Firefox will ask you waht you want to view the response in, choose notepad and you can see the json response. Read the caveats about JSONP in the Astoria documentation.
2) Use the helper tool which is an HTML page here [ http://astoria.sandbox.live.com/tools/raw.htm ]. You can’t use this online (I know ’cause I tried in my impatience!). You need to download it and add it into your project. It will then properly parse and display results.
So all this is just about querying, the “R” (read) in CRUD. Wait till you see the C, U & D. Watch for another post.
Sign up for my newsletter so you don't miss my conference & Pluralsight course announcements!