Thursday, October 4, 2007

Getting started with Astoria

Few weeks ago, the CTP refresh for VS 2008 Beta 2 of Astoria was released. Astoria is a really cool project based on .NET 3.0 (WFC), Entity Framework to provide pure HTTP access to SQL Server data.In order to play with it, first of all you need to install the following:

After installing all we need, we can create out first project - this post will describe the steps you need in order to do that.

Create new Web Application Project:


After I did it, I need to add new ADO.NET Entity model. On the Project menu, click 'Add new item' and select the ADO.NET Entity Data Model.


Now, the wizard will start. Select: Generate model from database.


Next we'll save the connection info


I checked the option to add connection string to web.config and that's what I got there:

<add name="NorthwindEntities" connectionString="metadata=~/bin/NorthWind.csdl|~/bin/NorthWind.ssdl|~/bin/NorthWind.msl;
provider=System.Data.SqlClient;provider connection string=&quot;Data Source=.\sqlexpress;Initial Catalog=Northwind;
Integrated Security=True&quot;"
providerName="System.Data.EntityClient" />

The next step we select the objects we want. I choose Tables only.


What we got so far? .edmx file was added to our project, which is the schema.


Next step we should add and setup Astoria service. We'll do it from the Project menu --> Add new item.


New class was generated, it's not full cause we should select the type of the service.


I added the NorthwindModel.NorthwindEntities type. (NorthwindModel is the model I generated)


Now everything ready to compile...

After compilation, I can browse to the service I created. Look what I got:


The service describes the schema with the object I selected (Tables only).

How can I query the service? For example, if I want all the categories, I'll change in the address in my browser to: http://localhost:58889/NorthwindWebDataService.svc/Categories and I got all the categories:

(localhost:58889 is on my computer off course, change your host:port to match yours)



What about query it from app? 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. You can find it at the installation folder.

What if I want to query the service to get the customers order by contact name:


and what if I want the top 10 records:



Astoria is set to provide the developers 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.


Technorati Tags: ,

No comments: