Your SlideShare is downloading. ×
0
Ado.Net Data Services (Astoria)
Ado.Net Data Services (Astoria)
Ado.Net Data Services (Astoria)
Ado.Net Data Services (Astoria)
Ado.Net Data Services (Astoria)
Ado.Net Data Services (Astoria)
Ado.Net Data Services (Astoria)
Ado.Net Data Services (Astoria)
Ado.Net Data Services (Astoria)
Ado.Net Data Services (Astoria)
Ado.Net Data Services (Astoria)
Ado.Net Data Services (Astoria)
Ado.Net Data Services (Astoria)
Ado.Net Data Services (Astoria)
Ado.Net Data Services (Astoria)
Ado.Net Data Services (Astoria)
Ado.Net Data Services (Astoria)
Ado.Net Data Services (Astoria)
Ado.Net Data Services (Astoria)
Ado.Net Data Services (Astoria)
Ado.Net Data Services (Astoria)
Ado.Net Data Services (Astoria)
Ado.Net Data Services (Astoria)
Ado.Net Data Services (Astoria)
Ado.Net Data Services (Astoria)
Ado.Net Data Services (Astoria)
Ado.Net Data Services (Astoria)
Ado.Net Data Services (Astoria)
Ado.Net Data Services (Astoria)
Ado.Net Data Services (Astoria)
Ado.Net Data Services (Astoria)
Ado.Net Data Services (Astoria)
Ado.Net Data Services (Astoria)
Ado.Net Data Services (Astoria)
Ado.Net Data Services (Astoria)
Ado.Net Data Services (Astoria)
Ado.Net Data Services (Astoria)
Ado.Net Data Services (Astoria)
Ado.Net Data Services (Astoria)
Ado.Net Data Services (Astoria)
Ado.Net Data Services (Astoria)
Ado.Net Data Services (Astoria)
Ado.Net Data Services (Astoria)
Ado.Net Data Services (Astoria)
Ado.Net Data Services (Astoria)
Ado.Net Data Services (Astoria)
Ado.Net Data Services (Astoria)
Ado.Net Data Services (Astoria)
Ado.Net Data Services (Astoria)
Ado.Net Data Services (Astoria)
Ado.Net Data Services (Astoria)
Ado.Net Data Services (Astoria)
Ado.Net Data Services (Astoria)
Ado.Net Data Services (Astoria)
Ado.Net Data Services (Astoria)
Ado.Net Data Services (Astoria)
Ado.Net Data Services (Astoria)
Ado.Net Data Services (Astoria)
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Ado.Net Data Services (Astoria)

4,015

Published on

Published in: Technology
1 Comment
1 Like
Statistics
Notes
No Downloads
Views
Total Views
4,015
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
0
Comments
1
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide
  • Transcript

    • 1. ADO.Net Data Services Astoria Enabling your data for Web consumption Igor Moochnick IgorShare Consulting [email_address] Blog: www.igorshare.com/blog
    • 2. 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
    • 3. Time to think “SERVICES” <ul><li>Multi-tenant deployments </li></ul><ul><li>Trust </li></ul><ul><li>Reach </li></ul><ul><li>Interaction </li></ul><ul><li>Administration </li></ul><ul><li>Resource Governance </li></ul>Mobile/ Desktop OLAP FILE XML RDBMS Query Analysis Reporting Integration Sync Search Server Data Services
    • 4. Data Services For RIAs Presentation & Behavior Data (XML, etc) Data Presentation, Behavior & Data
    • 5. 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 <ul><li>Refine access to the data service </li></ul><ul><li>Authorization policy </li></ul><ul><li>Concurrency </li></ul><ul><li>etc </li></ul>2
    • 6. Presentation & Behavior (HTML & JS) Data (XML, etc) Data Data Services For RIAs
    • 7. Presentation & Behavior (HTML & JS) Data (XML, etc) Data Store archived records in the cloud storage Data Services For RIAs
    • 8. 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
    • 9. A REST Interface For Data
    • 10. .NET vs. REST <ul><li>ADO.NET Data Services </li></ul><ul><li>Client included in .NET Framework 3.5 SP1 </li></ul><ul><li>Data represented as .NET objects </li></ul><ul><li>DataServiceContext methods for updates </li></ul><ul><li>Use LINQ to define queries </li></ul><ul><li>REST Interface </li></ul><ul><li>Use any HTTP stack </li></ul><ul><li>Data represented in Atom (XML) </li></ul><ul><li>Standard HTTP verbs for updates </li></ul><ul><li>Use URLs to define queries </li></ul>
    • 11. Creating Data Services <ul><li>Create services directly from Visual Studio </li></ul><ul><li>Various data sources </li></ul><ul><ul><li>Entity Framework </li></ul></ul><ul><ul><li>LINQ providers </li></ul></ul><ul><li>Model-driven </li></ul><ul><ul><li>Structural description in Entity Data Model </li></ul></ul><ul><ul><li>Metadata shapes service </li></ul></ul>Data Access Layer Entity Framework Custom LINQ provider Relational database Other sources Service Runtime Hosting/HTTP listener HTTP IQueryable [+ IUpdatable]
    • 12. Entity Framework ? SQL Provider Oracle Provider ... Entity Provider Conceptual Model Store Model Map ADO.NET API ORM API
    • 13. 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
    • 14. 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)
    • 15. Operations Semantics <ul><li>GET -> retrieve recourse </li></ul><ul><li>POST -> create resource </li></ul><ul><li>PUT -> update resource </li></ul><ul><li>DELTE -> delete resource </li></ul>
    • 16. Tip : force IE to show the feed XML <ul><li>Tools->Internet Options-> Content Tab </li></ul><ul><li>Click Settings button in the Feeds section </li></ul><ul><li>uncheck the Turn on Feed Reading View option </li></ul>Demo
    • 17. Data? What Kind of Data? <ul><li>Provide a type with public properties which are IQueryable<T> </li></ul><ul><ul><li>Some rules about how T has to be formed </li></ul></ul><ul><ul><li>Remember the extension method AsQueryable() </li></ul></ul><ul><li>Get write access if your type implements IUpdatable </li></ul><ul><li>Works well with generated code from: </li></ul><ul><ul><li>ADO.NET Entity Framework ( ObjectContext ) </li></ul></ul><ul><ul><li>LINQ to SQL ( DataContext *) </li></ul></ul>Demo
    • 18. ADO.NET Data Services payload <ul><li>ATOM/APP </li></ul><ul><li>JSON </li></ul><ul><li>Web3s (POX) - ??? </li></ul><ul><li>RDF - ??? </li></ul><ul><li>Controlled via Accept header </li></ul>
    • 19. Tools to explore the services <ul><li>JSON Viewer - http://www.codeplex.com/JsonViewer </li></ul><ul><li>Fiddler - http://www.fiddlertool.com/fiddler/ </li></ul><ul><li>Firebug - http://getfirebug.com/ </li></ul><ul><li>Raw.htm </li></ul><ul><li>Etc… </li></ul>Demo
    • 20. URL Conventions <ul><li>Addressing entities and sets </li></ul>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
    • 21. Operators for $filter
    • 22. Operators <ul><li>() – grouping </li></ul><ul><li>Arithmetic </li></ul><ul><ul><li>add </li></ul></ul><ul><ul><li>sub </li></ul></ul><ul><ul><li>mul </li></ul></ul><ul><ul><li>div </li></ul></ul><ul><ul><li>mod </li></ul></ul><ul><li>Logical </li></ul><ul><ul><li>and </li></ul></ul><ul><ul><li>not </li></ul></ul><ul><ul><li>eq </li></ul></ul><ul><ul><li>ne </li></ul></ul><ul><ul><li>lt </li></ul></ul><ul><ul><li>gt </li></ul></ul><ul><ul><li>le </li></ul></ul><ul><ul><li>ge </li></ul></ul>
    • 23. Query operators <ul><li>callback (specific to JSON for AJAX calls) </li></ul><ul><li>expand - pull related data using EDM associations </li></ul><ul><li>format - define format of the response (eg xml, json, rdf) </li></ul><ul><li>keyset- only return the entityKeys </li></ul><ul><li>orderby (you know what this is) </li></ul><ul><li>skip (same as in LINQ) </li></ul><ul><li>top </li></ul>Demo
    • 24. Addressing Pseudo-Members <ul><li>$metadata </li></ul><ul><ul><li>AdventureWorks.svc/$metadata </li></ul></ul><ul><li>$value </li></ul><ul><ul><li>AdventureWorks.svc/Customers(1)/FirstName/$value </li></ul></ul><ul><li>$batch </li></ul><ul><ul><li>AdventureWorks.svc/$batch </li></ul></ul>Demo
    • 25. Query Options <ul><li>Ordering </li></ul><ul><ul><li>$orderby [asc | desc] </li></ul></ul><ul><li>Paging </li></ul><ul><ul><li>$skip </li></ul></ul><ul><ul><li>$top </li></ul></ul><ul><li>Filtering </li></ul><ul><ul><li>$filter </li></ul></ul><ul><li>Eager-Loading </li></ul><ul><ul><li>$expand </li></ul></ul>Demo
    • 26. &quot;Traditional&quot; Applications <ul><li>Web applications </li></ul><ul><ul><li>Data services client can be used in ASP.NET </li></ul></ul><ul><ul><li>ASP.NET data source control for accessing remote services </li></ul></ul><ul><li>Desktop applications </li></ul><ul><ul><li>Fully-featured .NET client library </li></ul></ul><ul><ul><li>Same API in desktop and Silverlight environments </li></ul></ul>
    • 27. Modern Data-Driven Web Apps <ul><li>AJAX integration </li></ul><ul><ul><li>AJAX-friendly JSON format in services </li></ul></ul><ul><ul><li>Javascript library that integrates with the ASP.NET AJAX toolkit </li></ul></ul><ul><li>Silverlight support </li></ul><ul><ul><li>.NET programming model for data services </li></ul></ul><ul><ul><li>Object based, LINQ enabled API </li></ul></ul><ul><ul><li>Code-gen entity types from metadata </li></ul></ul>
    • 28. Building Clients <ul><li>Services offer metadata </li></ul><ul><ul><li>MyService.svc/$metadata </li></ul></ul><ul><li>.NET clients made easier through a proxy generation tool </li></ul><ul><ul><li>datasvcutil.exe </li></ul></ul><ul><ul><li>Useful for both regular .NET clients & Silverlight </li></ul></ul><ul><li>AJAX clients made easier through a script library </li></ul><ul><ul><li>“ Data Service AJAX Client Library” </li></ul></ul><ul><ul><li>Available as a download on Codeplex </li></ul></ul>Demo
    • 29. Creating new entity <ul><li>JSON </li></ul><ul><li>{ </li></ul><ul><li>    Name: “James&quot; </li></ul><ul><li>} </li></ul><ul><li>ATOM </li></ul><ul><li><entry  xmlns:d=“…&quot; </li></ul><ul><li>xmlns:m=“…&quot; </li></ul><ul><li>xmlns=&quot;http://www.w3.org/2005/Atom&quot;> </li></ul><ul><li>  <content type=&quot;application/xml&quot;> </li></ul><ul><li>    <m:properties> </li></ul><ul><li>      <d:Name>James</d:Name> </li></ul><ul><li>    </m:properties> </li></ul><ul><li>  </content> </li></ul><ul><li></entry> </li></ul>Demo
    • 30. Debugging tricks <ul><li>[System.ServiceModel.ServiceBehavior(IncludeExceptionDetailInFaults = true)] </li></ul><ul><li>InitializeService </li></ul><ul><ul><li>config.UseVerboseErrors = true; </li></ul></ul>Demo
    • 31. Interception & Operations <ul><li>Possible to hook code into the framework </li></ul><ul><li>For queries we can write </li></ul><ul><ul><li>Query interceptors </li></ul></ul><ul><li>For modifications we can write </li></ul><ul><ul><li>Change interceptors </li></ul></ul><ul><li>Can also expose custom functionality </li></ul><ul><ul><li>Service Operations </li></ul></ul><ul><ul><li>Useful for providing “canned” functionality, can be parameterised </li></ul></ul>Demo
    • 32. Refining and Securing Services Demo
    • 33. Astoria-offline <ul><li>you could point to a data service and say “take it offline”… </li></ul><ul><li>… a SQL Server Compact database automatically created and sync-enabled </li></ul><ul><li>You write a regular “local” application … </li></ul>Demo
    • 34. Scalable, Available Data Services Storage and Database Services <ul><li>Windows Azure Storage </li></ul><ul><li>“ Essential storage service in the cloud” </li></ul><ul><li>Provides a core set of non-relational storage and retrieval abstractions at massive scale </li></ul><ul><li>SQL Data Services </li></ul><ul><li>“ Premium database service in the cloud” </li></ul><ul><li>Extends the rich capabilities of the SQL data platform to the cloud at scale </li></ul><ul><ul><li>Relational data processing over structured and unstructured data </li></ul></ul><ul><ul><li>Integrate with key data platform capabilities – e.g. Data Analytics, Reporting, ETL </li></ul></ul>
    • 35. A Look Inside Azure
    • 36. Reference Data ETL Data Mining
    • 37. Data SYNC <ul><li>Occasionally connected (or disconnected) clients </li></ul><ul><ul><li>Mobile </li></ul></ul><ul><li>Mirroring </li></ul><ul><li>Future: Integration with ADO.NET Data Services </li></ul><ul><li>Enterprise Data Hub </li></ul>
    • 38. Enterprise Data Hub Sharing data through Data Sync <ul><li>Sharing data via the Internet </li></ul><ul><ul><li>Across devices and across enterprises </li></ul></ul><ul><li>Sharing data with offline capabilities (Sync) </li></ul><ul><li>Sharing data through a sync service </li></ul>Demo Sync Service iPhone Occasionally Connected Data Sharing
    • 39. Advanced Topics <ul><li>Optimistic concurrency </li></ul><ul><ul><li>If-Match: * </li></ul></ul><ul><ul><li>If-None-Match: * </li></ul></ul>
    • 40. Batching of Operations “ INSERT” Customer 1 POST Order 1 POST Order 2 POST Order N POST
    • 41. Batching of Operations “ INSERT” Customer 1 Order 1 Order 2 Order N POST
    • 42. Batching in code <ul><li>DataServiceResponse responses = proxy.ExecuteBatch ( new DataServiceRequest<Shippers>(new Uri(&quot;Shippers&quot;, UriKind.Relative)), new DataServiceRequest<Employees>(new Uri(&quot;Employees&quot;, UriKind.Relative))); </li></ul><ul><li>proxy.SaveChanges( SaveChangesOptions.Batch ); </li></ul>Demo
    • 43. Batching of Operations <ul><li>Provides a mechanism to process a batch </li></ul><ul><ul><li>0 or more Query operations </li></ul></ul><ul><ul><li>0 or more [Create/Update/Delete] operations </li></ul></ul><ul><li>Uses multipart/mixed MIME type sent to a $batch endpoint </li></ul><ul><li>Use </li></ul><ul><ul><li>SaveChanges(SaveChangesOptions.Batch) </li></ul></ul><ul><ul><li>ExecuteBatch() </li></ul></ul>
    • 44. Managing Concurrency GET GET Customer: ALFKI Country: Spain Customer: ALFKI Country: Spain
    • 45. Managing Concurrency PUT Customer: ALFKI Country: UK PUT Customer: ALFKI Country: Germany
    • 46. Managing Concurrency <ul><li>Optimistic concurrency </li></ul><ul><li>Attribute used to specify properties </li></ul><ul><ul><li>Not necessary for Entity Framework data </li></ul></ul><ul><li>Standard HTTP protocol used </li></ul><ul><ul><li>eTags used to send to client ( in XML if necessary ) </li></ul></ul><ul><ul><li>HTTP If-match headers used to check when PUT/DELETE occurs ( 412 returned for failure ) </li></ul></ul>Demo
    • 47. Resources <ul><li>Team Blog: </li></ul><ul><ul><li>http://blogs.msdn.com/astoriateam </li></ul></ul><ul><li>Online Forum </li></ul><ul><ul><li>http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=1430&SiteID=1 </li></ul></ul><ul><li>Using Microsoft ADO.NET Data Services (MSDN Technical Article) </li></ul><ul><ul><li>http://msdn.microsoft.com/en-us/library/cc907912.aspx </li></ul></ul>
    • 48. Q&A
    • 49. Thank you!
    • 50. ADO.Net Data Services Astoria Enabling your data for Web consumption Igor Moochnick IgorShare Consulting [email_address] Blog: www.igorshare.com/blog
    • 51.  
    • 52. AZURE TABLES - CODE
    • 53. Insert Entity using .NET <ul><li>Create a new Message and Insert into Table </li></ul>Message message = new Message { PartitionKey = &quot;Channel9&quot; , // ChannelName RowKey = DateTime .UtcNow.ToString(), // PostedDate Text = &quot;Hello PDC&quot; , Rating = 3 }; serviceUri = new Uri ( &quot;http://<account>.table.core.windows.net&quot; ); var context = new DataServiceContext (serviceUri); context.AddObject( &quot;Messages&quot; , message); DataServiceContext response = context.SaveChanges();
    • 54. <ul><li>Create an Atom XML payload and POST it </li></ul>Insert Entity using REST POST http://< Account> .table.core.windows.net/ Messages ... <!– Atom envelope --> < m:properties > < d:PartitionKey > Channel9 </ d:PartitionKey > <!-- ChannelName --> < d:RowKey > Oct-29 </ d:RowKey > <!-- PostedDate --> < d:Text > Hello PDC </ d:Text > < d:Rating > 3 </ d:Rating > </ m:properties >
    • 55. Query Entities serviceUri = new Uri ( &quot;http://<account>.table.core.windows.net&quot; ); DataServiceContext context = new DataServiceContext (serviceUri); var messages = from message in context.CreateQuery< Message >( &quot;Messages&quot; ) where message.Rating == 3 select message; foreach ( Message message in messages) { } GET http:// <serviceUri> /Messages?$filter= Rating eq 3
    • 56. Update a property in an entity <ul><li>Using the .NET API </li></ul>Message message = ( from message in context.CreateQuery< Message >( &quot;Messages&quot; ) where message.PartitionKey == &quot;Channel9&quot;   && message.RowKey == &quot;Oct-29&quot; select message).FirstOrDefault(); message.Text = &quot;Hi there&quot; ; 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 >
    • 57. <ul><li>Using the .NET API </li></ul>Delete an Entity // Get the Message object for ( &quot;Channel9&quot; , &quot;Oct-29&quot; ) context.DeleteObject(message); DataServiceResponse response = context.SaveChanges(); DELETE http://.../Messages(‘Channel9’, ‘ Oct-29’)
    • 58. <ul><li>.NET: LINQ Take(N) function </li></ul>Getting the Top N entities serviceUri = new Uri ( &quot;http://<account>.table.core.windows.net&quot; ); DataServiceContext context = new DataServiceContext (serviceUri); var allMessages = context.CreateQuery< Message >( &quot;Messages&quot; ); foreach ( Message message in allMessages.Take(100)) { Console .WriteLine(message.Name); } GET http://< serviceUri> /Messages?$top=100

    ×