Very good presentation, Its been very helpful in my project to interact database with Flex applications. Now is a process very easy to put to run just 5 minutes, only tools needed 1.Visual Web Developer 2008 SP1 Express Edition 2.Any database Sql Server Based or File Access based 3.Hosting company that support Framework 3.5 and .svc extensions support. More References: http://emiliovick.wordpress.com/2009/10/15/wcf-restful-example-with-visual-web-developer-2008-experience/
Ado.Net Data Services (Astoria) - Presentation Transcript
ADO.Net Data Services Astoria Enabling your data for Web consumption Igor Moochnick IgorShare Consulting [email_address] Blog: www.igorshare.com/blog
Data on the Web HTML + Javascript Data (XML,JSON,…) DLL + XAML Data (XML,JSON,…) Data (XML,JSON,…) Mashup UI Data Feeds AJAX Applications Silverlight Applications Online Services Mashups
Time to think “SERVICES”
Multi-tenant deployments
Trust
Reach
Interaction
Administration
Resource Governance
Mobile/ Desktop OLAP FILE XML RDBMS Query Analysis Reporting Integration Sync Search Server Data Services
Data Services For RIAs Presentation & Behavior Data (XML, etc) Data Presentation, Behavior & Data
Presentation & Behavior Data (XML, etc) Data Presentation, Behavior Data Services For RIAs Create an on- premises data service 1 Consume the data service from RIA 3
Refine access to the data service
Authorization policy
Concurrency
etc
2
Presentation & Behavior (HTML & JS) Data (XML, etc) Data Data Services For RIAs
Presentation & Behavior (HTML & JS) Data (XML, etc) Data Store archived records in the cloud storage Data Services For RIAs
RESTful Web Services? Resources Res 1 Res 2 Res 3 Res 4 HTTP Request URL VERB Payload HTTP Response Status GET POST PUT DELETE XML JSON Payload XML JSON
A REST Interface For Data
.NET vs. REST
ADO.NET Data Services
Client included in .NET Framework 3.5 SP1
Data represented as .NET objects
DataServiceContext methods for updates
Use LINQ to define queries
REST Interface
Use any HTTP stack
Data represented in Atom (XML)
Standard HTTP verbs for updates
Use URLs to define queries
Creating Data Services
Create services directly from Visual Studio
Various data sources
Entity Framework
LINQ providers
Model-driven
Structural description in Entity Data Model
Metadata shapes service
Data Access Layer Entity Framework Custom LINQ provider Relational database Other sources Service Runtime Hosting/HTTP listener HTTP IQueryable [+ IUpdatable]
Entity Framework ? SQL Provider Oracle Provider ... Entity Provider Conceptual Model Store Model Map ADO.NET API ORM API
ADO.Net Data Services Alignment Data Service Support Client Support ADO.Net Data Services (Astoria) SQL Data Service Evolves to include flex entities Evolves to include schematized data Schematized Data Flex Entities
Exploring Data Services HTTP (AtomPub) Clients (Tools, Libraries, etc) SQL Data Services ADO.NET Data Services Framework SQL Server (On premises data service) (Cloud data service)
Operations Semantics
GET -> retrieve recourse
POST -> create resource
PUT -> update resource
DELTE -> delete resource
Tip : force IE to show the feed XML
Tools->Internet Options-> Content Tab
Click Settings button in the Feeds section
uncheck the Turn on Feed Reading View option
Demo
Data? What Kind of Data?
Provide a type with public properties which are IQueryable<T>
Some rules about how T has to be formed
Remember the extension method AsQueryable()
Get write access if your type implements IUpdatable
Works well with generated code from:
ADO.NET Entity Framework ( ObjectContext )
LINQ to SQL ( DataContext *)
Demo
ADO.NET Data Services payload
ATOM/APP
JSON
Web3s (POX) - ???
RDF - ???
Controlled via Accept header
Tools to explore the services
JSON Viewer - http://www.codeplex.com/JsonViewer
Fiddler - http://www.fiddlertool.com/fiddler/
Firebug - http://getfirebug.com/
Raw.htm
Etc…
Demo
URL Conventions
Addressing entities and sets
Presentation options Demo Entity-set /Students Single entity /Students(1) Member access /Students(1)/Name Link traversal /Students(1)/ClassRegistrations Deep access /Students(1)/ClassRegistrations(2)/Grade Raw value access /Students(1)/Photo/$value Sorting /Students?$orderby=Name desc Filtering /Classes?$filter=substringof(Name, ‘Math’) Paging /Students?$top=10&$skip=30 Inline expansion /Students?$expand=ClassRegistrations
Operators for $filter
Operators
() – grouping
Arithmetic
add
sub
mul
div
mod
Logical
and
not
eq
ne
lt
gt
le
ge
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
Demo
Addressing Pseudo-Members
$metadata
AdventureWorks.svc/$metadata
$value
AdventureWorks.svc/Customers(1)/FirstName/$value
$batch
AdventureWorks.svc/$batch
Demo
Query Options
Ordering
$orderby [asc | desc]
Paging
$skip
$top
Filtering
$filter
Eager-Loading
$expand
Demo
"Traditional" Applications
Web applications
Data services client can be used in ASP.NET
ASP.NET data source control for accessing remote services
Desktop applications
Fully-featured .NET client library
Same API in desktop and Silverlight environments
Modern Data-Driven Web Apps
AJAX integration
AJAX-friendly JSON format in services
Javascript library that integrates with the ASP.NET AJAX toolkit
Silverlight support
.NET programming model for data services
Object based, LINQ enabled API
Code-gen entity types from metadata
Building Clients
Services offer metadata
MyService.svc/$metadata
.NET clients made easier through a proxy generation tool
datasvcutil.exe
Useful for both regular .NET clients & Silverlight
Query Entities serviceUri = new Uri ( "http://<account>.table.core.windows.net" ); DataServiceContext context = new DataServiceContext (serviceUri); var messages = from message in context.CreateQuery< Message >( "Messages" ) where message.Rating == 3 select message; foreach ( Message message in messages) { } GET http:// <serviceUri> /Messages?$filter= Rating eq 3
Update a property in an entity
Using the .NET API
Message message = ( from message in context.CreateQuery< Message >( "Messages" ) where message.PartitionKey == "Channel9" && message.RowKey == "Oct-29" select message).FirstOrDefault(); message.Text = "Hi there" ; context.UpdateObject(message); DataServiceResponse response = context.SaveChanges(); PUT http:// <serviceUri> /Messages(‘Channel9’, ‘ Oct-29’) < m:properties > < d:Text > Hi there </ d:Text > <!-- Other properties are the same --> </ m:properties >
Using the .NET API
Delete an Entity // Get the Message object for ( "Channel9" , "Oct-29" ) context.DeleteObject(message); DataServiceResponse response = context.SaveChanges(); DELETE http://.../Messages(‘Channel9’, ‘ Oct-29’)
.NET: LINQ Take(N) function
Getting the Top N entities serviceUri = new Uri ( "http://<account>.table.core.windows.net" ); DataServiceContext context = new DataServiceContext (serviceUri); var allMessages = context.CreateQuery< Message >( "Messages" ); foreach ( Message message in allMessages.Take(100)) { Console .WriteLine(message.Name); } GET http://< serviceUri> /Messages?$top=100
1 comments
Comments 1 - 1 of 1 previous next Post a comment