WeWantWeb - WCF Data Services

24
OData e WCF Data Services: dati a portata di Web Pietro Libro [email protected] http://blogs.ugidotnet.org/ PietroLibroBlog Twitter: pietrolibro

description

Sessione "WCF Data Services" tenuta da Pietro Libro durante l'evento "WWW - We Want Web" di DomusDotNet

Transcript of WeWantWeb - WCF Data Services

Page 1: WeWantWeb - WCF Data Services

OData e WCF Data Services: dati a portata di Web

Pietro [email protected]

http://blogs.ugidotnet.org/PietroLibroBlog

Twitter: pietrolibro

Page 2: WeWantWeb - WCF Data Services

2

Agenda

• Open Data Protocol (OData)• WCF Data Services

– Query\CRUD– Service Operations– Cache & Security

Page 3: WeWantWeb - WCF Data Services

3

Problema…

Page 4: WeWantWeb - WCF Data Services

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

Page 5: WeWantWeb - WCF Data Services

5

OData• Non solo database !

Page 6: WeWantWeb - WCF Data Services

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

Page 7: WeWantWeb - WCF Data Services

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

Page 8: WeWantWeb - WCF Data Services

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…

Page 9: WeWantWeb - WCF Data Services

9

DEMO

Page 10: WeWantWeb - WCF Data Services

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

Page 11: WeWantWeb - WCF Data Services

11

Page 12: WeWantWeb - WCF Data Services

12

WCF Data Services

Page 13: WeWantWeb - WCF Data Services

13

WCF Data Services

DEMO

Page 14: WeWantWeb - WCF Data Services

14

WCF Data Services

Anatomia di una query

Page 15: WeWantWeb - WCF Data Services

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

Page 16: WeWantWeb - WCF Data Services

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

Page 17: WeWantWeb - WCF Data Services

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<…>

Page 18: WeWantWeb - WCF Data Services

18

WCF Data Services : Service Operations

…ancora:

• WebGet [GET]• WebInvoke(Method=«POST») [POST]

Page 19: WeWantWeb - WCF Data Services

19

WCF Data Services

Query, Service Operations, Eager & Explicit Loading, Add/Update/Delete

DEMO

Page 20: WeWantWeb - WCF Data Services

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...

Page 21: WeWantWeb - WCF Data Services

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

Page 22: WeWantWeb - WCF Data Services

22

WCF Data Services

Cache & Security

DEMO

Page 24: WeWantWeb - WCF Data Services

Un grazie a.....