After reading the title of this article you were probably brought here by curiosity “what is Astoria?”
Astoria is a new technology from Microsoft that builds on an established technology Windows
Communication Foundation (
WCF) and a soon to be de facto data access layer (
technology called Entity Data Model (
EDM) which is due for release some time after the Orcas line of
Astoria got released at Mix ’07 in the form of a Community Technology Preview (CTP); this is the
first chance that we have had to look at
Astoria uses familiar standards based mechanisms to access conceptual data defined in an
EDM. We do this by using standard
HTTP verbs like
So why the fuss?
Astoria is something that rich internet applications (RIA’s) can really take
advantage of. By firing off asynchronous requests to a server using a uniform resource identifier (
URI) from your chose technology you can really take advantage of Astoria web data services.
I must admit
Astoria is one of those technologies that genuinely get’ me excited – anyone who has
ASP.NET AJAX application and has fired requests off to web service methods which are fairly
static in their composition will really like this technology.
Creating an Astoria Data Service
I mentioned earlier that
Astoria is built on two technologies namely
EDM. It should come as no surprise then that we need to create each – but we do have some aid
provided in the form of new item templates in Visual Studio Orcas Beta 1.
wizard comes with Visual Studio Orcas Beta 1, the
CTP does not and you will have to download this from the Microsoft downloads site
My intention is to not make this a tutorial but rather an informal chat about
Astoria and as such I
will talk lightly about the steps involved in creating an
Astoria data service but I will not go
into the explicit steps required.
First thing is first, we need to create an
EDM model for our database I have chosen to use the
popular Northwind database. This
EDM will be used when creating our
The second step to getting an
Astoria data service up and running is to actually add a “Web Data
Service” item to your web application project.
Figure 1-1: Adding a Web Data Service to your application
With the web data service added you need to go into the code behind for that service and derive from the
XxxEntities type which the
EDM wizard generated for you.
XxxEntities type is defined in a namespace
Xxx in each case is normally the name of the target database, e.g. the Northwind namespace generated
I decided to host my
Astoria services using IIS 7 however you can do this using IIS 6, but I haven’t
When you browse to your service you will see a container XML element called
contains all the entity children that the
EDM wizard generated for us. Each entity maps 1..1 with
physical tables in your database unless you chose to customize the mappings.
Note: The service endpoint has a file extension of .svc to indicate it is a
Figure 1-2: Viewing the service endpoint
You can see that in Figure 1-2 I have several entities available to me from my
Astoria web data
service - Suppliers, Products, Orders, etc...
Consuming the service using the Microsoft AJAX Library
In this article I am going to use
ASP.NET AJAX to query the
Astoria web data service,
you can however use pretty much any technology – I myself have used
ASP.NET AJAX, several windows
applications as well as
WPF (and it’s binding syntax) to use
Astoria, each with minimal
Just before we see some code I would like to point out that ASP.NET Futures does provide support for consuming
Astoria web data services – I have chosen not to use this however to reach a wider audience, after
all everyone is still learning
ASP.NET AJAX 1.0! The API introduced into ASP.NET Futures really
isn’t that much of a big deal; it just removes a few steps that are a little “dirty” as you will see in the
ASP.NET AJAX we are familiar with sending some async request to a web server and receiving some
data back – this is a paradigm established with
AJAX applications where we separate the
presentation, behaviour and data. Commonly the presentation is
HTML, the behaviour is
Astoria web data services support three types of data exchange format including:
For this article we will, of course, be using
JSON allows us to interact
with objects after eval’ing the
JSON string passed to us from the server.
I think for the first query let’s just go ahead and retrieve all of the customers.
Listing 1-1: Retrieving all of the customers
Note: There is a class that comes with the
Astoria samples that provides a class and series
of methods to create a more encapsulated approach to calling an
Astoria web data service.
Figure 1-3: Running Listing 1-1.
It’s not my intention to go through the various filtering syntax in this article or all of the features provided
Astoria web data services like adding, updating and deleting data.
Before I wrap this up let’s take a lot at some queries where we use the URI to further filter the results.
Listing 1-2: Ordering the results by ContactName
Listing 1-3: Selecting the top 10 results from Listing 1-2.
Astoria is set to provide RIA developers with a richer way of interacting with data on the server.
The syntax is easy and there is a more structure API on the way for
ASP.NET AJAX in ASP.NET Futures
Astoria CTP samples).
Go and download the CTP bits and give it a go!
Sorry, no bio is available
This author has published 32 articles on DotNetSlackers. View other articles or the complete profile here.
Please login to rate or to leave a comment.