1. OData e WCF Data Services:
dati a portata di Web
Pietro Libro
Pietro.libro@domusdotnet.org
http://blogs.ugidotnet.org/PietroLibroBlog
Twitter: pietrolibro
2. Agenda
• Open Data Protocol (OData)
• WCF Data Services
– QueryCRUD
– Service Operations
– Cache & Security
2
4. …soluzione: OData
• Protocollo Web: interrogazione ed aggiornamento dati
• Utilizza tecnologie Web: HTTP, AtomPub, JSON
• Modello astratto dei dati: URI per identificare le risorse
• Rilasciato sotto Microsoft Open Specification Promise
4
6. OData
• Feeds : collezione di Entries tipizzate
– Una Entry è una struttura contente proprietà
• Proprietà: tipi primitivi o tipi complessi
– Una Entry può far parte di una struttura gerarchica o essere isolata
• Relazione tra entry tramite Link
– Entry sono speciali (Media Element)
• Media Link Entry
• Media Resource
• Service Operations
– Funzioni che accettano parametri e restituiscono tipi complessi o
primitivi
6
7. OData
• Metadata:
– Service Document con la lista di tutti i Feeds
• Lista ad alto livello di tutti i Feeds
• Utile per associare ogni Feed ad un indirizzo
– Service Metadata Document
• Documento che descrive l’Entity Data Model per uno
specifico servizio
• Esposto come End-point
7
8. OData : www.odata.org
• Alcune applicazioni «OData Publisher»:
– Microsoft Sharepoint 2010
– Microsoft Windows Azure Table Storage
– Sql Server Reporting Services
– OData per Team Foundation Server
– IBM WebShpere
• Librerie per interagire con:
– Microsoft .Net
– Windows Phone 7
– Microsoft Silverlight
– PHP
– Objective-C
– Ecc…
8
10. WCF Data Services
• Conosciuti anche come ADO.NET Services (codename
«Astoria»)
• Basati su
– Open Data Protocol
– REST (Representational State Transfer, Thomas Fielding)
• Descrive le risorse presenti nel Web
• Risorsa, univocamente determinata da un indirizzo
• GET, POST, PUT e DELETE
10
15. WCF Data Services : Query
• Per applicare un «filtro» è possibile utilizzare la Keyword
$filter
• Operatori di uguaglianza
• Confronto
• Operatori logici
• Operazioni matematiche
• Funzioni booleane applicabili a stringhe
• Funzioni per le date
• Funzioni di arrotondamento
15
16. WCF Data Services : Service Operations
• Logica di Business sui dati
• REST
• Requisiti
– Public, membro di DataService<T>
– Parametri di Input «Primitivi»
– Il valore di ritorno può essere:
• Void
• IEnumerable
• IQueryable
• Un’entità (ad esempio Recipe, Glass)
• Tipo Primitivo
16
17. WCF Data Services : Service Operations
• Per operazioni di:
– Filtering
– Paging
– Sorting
• Per utilizzare
– Query Option
– Accesso ai Link (entità collegate)
E’ necessario ritornare IQueryable<…>
17
18. WCF Data Services : Service Operations
…ancora:
• WebGet [GET]
• WebInvoke(Method=«POST») [POST]
18
19. WCF Data Services
Query, Service Operations, Eager & Explicit
Loading, Add/Update/Delete
DEMO
19
20. WCF Data Services : Cache & Security
• Costruiti sull’infrastruttura ASP.NET
• Cache
– Possiamo utilizzarne tutte le varie features
• Output caching
• Custom OutputCacheProvider
• Memory Cache
• Enterprise Library
• Ecc...
20
21. WCF Data Services : Cache & Security
• Costruiti sull’infrastruttura ASP.NET
• Security
– Query Interceptors
– Anonymous Authentication
– Basic-Digest Authentication
– Windows Authentication
– ASP.NET Forms Authentication
– Claims-Based Authentication
– WIF
21