SlideShare a Scribd company logo
Building RESTfull
Data Services
with WebAPI
Gert Drapers (#DataDude)
Principle Software Design Engineer
Agenda
•Overview
•OData Core Libraries
•Web API
•Web API Demo
Overview
OData Value Proposition
• Problem Statement:
• There is no consistent data interoperability protocol for addressing
and manipulating enterprise data across various devices and
platforms
• Value Proposition:
• OData enables consistent REST-based data access from a variety
of back ends including relational databases, file systems, content
management systems, and traditional Web sites
• OData builds on widely-accepted standards like HTTP, JSON,
AtomPub, and URIs to address and access data
What OData Is and Is Not?
• What OData Is:
• Easy, consistent data access via HTTP endpoints
• REST-based data operations: CRUD, Filtering, Sorting, Paging,
Custom Operations, Delta, etc.
• Service centric data definition, operation and annotation
• Schematized and schema-less data sets
• Broadly accepted JSON/ATOM format on the wire
• What OData Is Not:
• Not to replace native or direct data access interface, e.g. ODBC/TDS
for SQL
• Not to replace highly specialized BI technologies like XMLA
OData Status
• OData v4 to be standardized in Feb. in OASIS
• http://docs.oasis-open.org/odata/new-in-odata/v4.0/cn01/new-in-odata-v4.0-
cn01.html
• ODL 6.2
• http://blogs.msdn.com/b/odatateam/archive/2014/04/14/odl-6-2-release-
announcement.aspx
• Web API OData 6.1
• http://blogs.msdn.com/b/odatateam/archive/2014/03/21/odata-6-1-and-odata-
client-6-1-are-now-shipped.aspx
• WCF Data Services moved to OSS
• http://blogs.msdn.com/b/odatateam/archive/2014/03/27/future-direction-of-wcf-
data-services.aspx
http://odata.org/
OData Core Libraries
Technology Basics
Client Server
OData Service
OData
Protocol
Library
OData
Data
Model
Library
Data
Source
Technology .NET
OData Data Model Library Microsoft.odata.edm.dll
OData Protocol Library Microsoft.odata.core.dll
OData Service WCF Data Service/ Web API/ User’s own service
OData Client Library Microsoft.odata.client.dll
Code Generator T4 / item template
OData
Protocol
Library
OData
Data
Model
Library
OData Client
Library
OData
Protocol
Library
OData
Data
Model
Library
How to build client to consume
OData
Business Logic
Dev OData
Service
Metadata request
Use Code Generatror to generate client class
Client
Application
Account account = TestClientContext.Accounts.Where(account => account.AccountID
== 110).Single();
account.Country=”US”;
TestClientContext.UpdateObject(account);
TestClientContext.SaveChanges();
Code Files(Account.cs/
TestClientContext.cs)
Microsoft.odata.client.dll
The client dll will generate the request
based on the property change on the Account object
Get http://localhost:8080/OData/Accounts(110)
Patch http://localhost:8080/OData/Accounts(110)
What’s in Microsoft.OData.Client.dll
•Deserialize/Serialize OData payload
• Using API provided by Microsoft.OData.Core.dll
•Request Generator/LINQ to URL
•Entity Tracker
•Batch support
OData Data Model Library
• OData is based on the Entity Data Model (EDM):
• EDM presents information in a way which is familiar to
many developers dealing with data today making it
easy for them to understand and use.
• Data provider can use OData Data Model Library to
create the EDM model of the data they want to
expose. The client can consume the data based on
the EDM model that exposed by service and figure
out the relationship between entities.
EDM Example
Entity Container
Entity set
(Categories)
Category
CategoryId Product
Entity set
(Products)
Product
ProductId Description
Navigation property binding
EDM Example – Cont.
• <?xml version="1.0" encoding="utf-8"?>
<edmx:Edmx Version="4.0" xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx">
<edmx:DataServices>
<Schema Namespace="Microsoft.Test.OData.Services.ODataWCFService" xmlns="http://docs.oasis-open.org/odata/ns/edm">
<EntityType Name="Category">
<Key>
<PropertyRef Name="CategoryId" />
</Key>
<Property Name="CategoryId" Type="Edm.String" Nullable="false" />
<Property Name="Name" Type="Edm.String" Nullable="false" />
<NavigationProperty Name="Product" Type="Microsoft.Test.OData.Services.ODataWCFService.Product" Nullable="false" />
</EntityType>
<EntityType Name="Product">
<Key>
<PropertyRef Name="ProductId" />
</Key>
<Property Name="ProductId" Type="Edm.String" Nullable="false" />
<Property Name="Name" Type="Edm.String" Nullable="false" />
<Property Name="Desciption" Type="Edm.String" Nullable="false" />
</EntityType>
<EntityContainer Name="ServiceContainer">
<EntitySet Name="Categories" EntityType="Microsoft.Test.OData.Services.ODataWCFService.Category">
<NavigationPropertyBinding Path="Product" Target="Products" />
</EntitySet>
<EntitySet Name="Products" EntityType="Microsoft.Test.OData.Services.ODataWCFService.Product">
</EntitySet>
</EntityContainer>
</Schema>
</edmx:DataServices>
</edmx:Edmx>
EDM Example – Cont.
• Category Entity:
• http://localhost/odata/Categories(1)
• Product under this category
• http://localhost/odata/Categories(1)/Product
• Through navigation binding defined in the Categories
and the navigation property defined in the Category,
target entity set Products can be found
• Entity product can be located in entity set Products
OData Protocol Library
• Deserialize/Serialize payload
• JSON
• Full metadata level
– {
– "@odata.context":"http://localhost:50671/ODataService.svc/OData/$metadata#Products/$entity",
– "@odata.id":"http://localhost:50671/ODataService.svc/OData/Products(5)",
– "@odata.editLink":"http://localhost:50671/ODataService.svc/OData/Products(5)",
– "ProductID":5,
– "Name":"Cheetos",
– "Description":"Cheese curl"
– }
• Minimal metadata level
– Writer only writes the necessary metadata
– Reader will auto complete the metadata during reading
– {
– "@odata.context":"http://localhost:50671/ODataService.svc/OData/$metadata#Products/$entity",
– "ProductID":5,
– "Name":"Cheetos",
– "Description":"Cheese curl"
– }
• No metadata level
– Data only
– {
– "ProductID":5,
– "Name":"Cheetos",
– "Description":"Cheese curl"
– }
• ATOM
OData Protocol Library
• Targeting the target resource based on the URI
• $top=n: Returns only the first n entities in an entity set (or in Atom terms,
the first n entries in a feed)
• $skip=n: Skips the first n entities in an entity set. Using this option lets a
client retrieve a series of distinct pages on subsequent requests
• $format: Determines whether data should be returned in JSON or the XML-
based Atom/AtomPub format
• $orderby=: Orders results, in ascending or descending order, by the value
of one or more properties in those results
• $filter=: Returns only entities that match the specified expression
• $select=: Returns only the specified properties in an entity
• $expand=: Returns the navigation property in an entity
URI Parser
OData Protocol Library – Cont.
• http://services.odata.org/V3/Northwind/Northwind.svc/Order_Details?$top=5
&$select=OrderID,ProductID&$skip=1&$filter=OrderID gt 10248
• Parsed result of request URI as an ODataUri object
• TopCount
• SkipCount
• SelectExpandClause
• List<SelectedItem>
– PathSelectionItem
» Path=OrderID
– PathSelectionItem
» Path=ProductID
• FilterClause
• FilterExpression
OData Web API
WebApi.OData: Overview
•An OData service library
•Build upon a lightweight http stack
•Be part of ASP.NET RESTful framework
•Selective query ability
•Another option to build OData service
Simple way to build OData Service
•No need to know the details of OData Protocol
•POCO (Plain Old CLR Object) model
•ODataConventionModelBuilder: 3 lines of code
var builder = new ODataConventionModelBuilder();
builder.EntitySet<Product>("Products");
IEdmModel model = builder.GetEdmModel();
•ODataController: VS2013 scaffolding
Web API OData Architecture Diagram
Message Handler
Controller Selection
ODataController
Action
Action Filter
MapODataRoute*GetEdmModelModel builderEdm Lib
Spatial Lib
Formatter
OData Lib
Serialize
Deserialize
Query
Entity Framework
DbContext
DbSet
Action Filter
Formatter Model Binder QueryOption
Action Selection
Type system
HttpRequestMessage
HttpResponseMessage
Components
• Model builder
• ODataModelBuilder
• ODataConventionModelBuilder (a 3 lines of code approach)
• Query
• ODL Semantic AST -> LINQ Expression (IQueryable) -> LINQ to * (Entities,
Objects…)
• Routing
• Conventional
• Attribute route
• Formatter
• Serializer: CLR type / typeless -> OData*Value
• Deserializer: OData*Value -> CLR type / typeless
Routing Examples
// Metadata routes to support $metadata and code generation in the
// WCF Data Service client.
configuration.Routes.MapHttpRoute(
ODataRouteNames.Metadata,
"$metadata",
new { Controller = "ODataMetadata", Action = "GetMetadata" }
);
configuration.Routes.MapHttpRoute(
ODataRouteNames.ServiceDocument,
"",
new { Controller = "ODataMetadata", Action = "GetServiceDocument" }
);
Routing Examples…
// Relationship routes (notice the parameters is {type}Id not id,
// this avoids colliding with GetById(id)).
// This code handles requests like ~/ProductFamilies(1)/Products
configuration.Routes.MapHttpRoute(
ODataRouteNames.PropertyNavigation,
"{controller}({parentId})/{navigationProperty}");
// Route for manipulating links, the code allows people to create and
// delete relationships between entities
configuration.Routes.MapHttpRoute(
ODataRouteNames.Link,
"{controller}({id})/$links/{navigationProperty}");
Routing Examples…
// Routes for urls both producing and handling URLs
// like: ~/Product(1), ~/Products() and ~/Products
configuration.Routes.MapHttpRoute(
ODataRouteNames.GetById,
"{controller}({id})");
configuration.Routes.MapHttpRoute(
ODataRouteNames.DefaultWithParentheses,
"{controller}()");
configuration.Routes.MapHttpRoute(
ODataRouteNames.Default,
"{controller}");
Model Builder
• ODataConventionModelBuilder
• Use reflection and conventions to generate an Edm model
• Reflection
• Type
• PropertyInfo
• MethodInfo
• Conventions
• AttributeConvention
• AttributeEdmTypeConvention: [DataContract]
• AttributeEdmPropertyConvention:
• [Key]
• [DataMember]
• [IgnoreDataMember]
• [Required]
• [ConcurrencyCheck]…
ODataModelBuilder
• Take full control
var builder = new ODataModelBuilder();
var products =
builder.EntitySet<Product>("Products");
var product = products.EntityType;
product.HasKey(p => p.ID);
product.Property(p => p.Name);
var rate = product.Action("Rate");
rate.Parameter<int>("Rating");
rate.Returns<double>();
• EntitySetConfiguration
• EntityTypeConfiguration
• PropertyConfiguration
• ProcedureConfiguration
• ParameterConfiguration
Query
• /Products/?$filter=Name eq ‘abc’
• One key differentiator than other Web API implementations
• QueryableAttribute
[Queryable]
public IQueryable<Product> GetProducts()
{
return db.Products;
}
• => ODataQueryOptions
public IEnumerable<Product> GetProducts(ODataQueryOptions options)
{
return options.ApplyTo(db.Products) as IEnumerable<Product>;
}
• FilterQueryOption -> FilterBinder:
• Convert OData AST FilterClause’s QueryNode to Linq Expression
Routing
• IODataRoutingConvention
• string SelectController(ODataPath odataPath, HttpRequestMessage request);
• string SelectAction(ODataPath odataPath, HttpControllerContext controllerContext,
ILookup<string, HttpActionDescriptor> actionMap);
• Convention based route:
• EntitySetRoutingConvention
• EntityRoutingConvention
• ActionRoutingConvention
• FunctionRoutingConvention
• NavigationRoutingConvention
• PropertyRoutingConvention
• Attribute based route:
• AttributeRoutingConvention
• ODataRouteAttribute
• MapODataRoute
Formatter
• Why does webapi.odata need to handle serialization and
deserialization?
• ODL handles OData object model to Payload
• Web API handles POCO to OData OM
• The hook:
[ODataFormatting]
public abstract class ODataController : ApiController
• ODataFormattingAttribute
• Inserts the ODataMediaTypeFormatters into the HttpControllerSettings.Formatters
collection.
• Attaches the request to the OData formatter instance.
• ODataMediaTypeFormatter.Create()
• ODataSerializerProvider / ODataDeserializerProvider
• OData*Serializer / OData*Deserializer
Demo
Build an OData Web API application
Laat ons weten wat u vindt van deze sessie! Vul de evaluatie
in via www.techdaysapp.nl en maak kans op een van de 20
prijzen*. Prijswinnaars worden bekend gemaakt via Twitter
(#TechDaysNL). Gebruik hiervoor de code op uw badge.
Let us know how you feel about this session! Give your
feedback via www.techdaysapp.nl and possibly win one of
the 20 prices*. Winners will be announced via Twitter
(#TechDaysNL). Use your personal code on your badge.
* Over de uitslag kan niet worden gecorrespondeerd, prijzen zijn voorbeelden – All results are final, prices are
examples
Building RESTfull Data Services with WebAPI
Ad

More Related Content

What's hot (20)

Identity and Access Management 101
Identity and Access Management 101Identity and Access Management 101
Identity and Access Management 101
Jerod Brennen
 
Data lineage and observability with Marquez - subsurface 2020
Data lineage and observability with Marquez - subsurface 2020Data lineage and observability with Marquez - subsurface 2020
Data lineage and observability with Marquez - subsurface 2020
Julien Le Dem
 
Threat-Based Adversary Emulation with MITRE ATT&CK
Threat-Based Adversary Emulation with MITRE ATT&CKThreat-Based Adversary Emulation with MITRE ATT&CK
Threat-Based Adversary Emulation with MITRE ATT&CK
Katie Nickels
 
Beyond REST and RPC: Asynchronous Eventing and Messaging Patterns
Beyond REST and RPC: Asynchronous Eventing and Messaging PatternsBeyond REST and RPC: Asynchronous Eventing and Messaging Patterns
Beyond REST and RPC: Asynchronous Eventing and Messaging Patterns
Clemens Vasters
 
Data Warehouse Fundamentals
Data Warehouse FundamentalsData Warehouse Fundamentals
Data Warehouse Fundamentals
Rashmi Bhat
 
ETL QA
ETL QAETL QA
ETL QA
dillip kar
 
Introduction to the Semantic Web
Introduction to the Semantic WebIntroduction to the Semantic Web
Introduction to the Semantic Web
Marin Dimitrov
 
Etl techniques
Etl techniquesEtl techniques
Etl techniques
mahezabeenIlkal
 
Introduction to OpenID Connect
Introduction to OpenID Connect Introduction to OpenID Connect
Introduction to OpenID Connect
Nat Sakimura
 
Kylin and Druid Presentation
Kylin and Druid PresentationKylin and Druid Presentation
Kylin and Druid Presentation
argonauts007
 
Debunking some “RDF vs. Property Graph” Alternative Facts
Debunking some “RDF vs. Property Graph” Alternative FactsDebunking some “RDF vs. Property Graph” Alternative Facts
Debunking some “RDF vs. Property Graph” Alternative Facts
Neo4j
 
Red Team P1.pdf
Red Team P1.pdfRed Team P1.pdf
Red Team P1.pdf
soheil hashemi
 
Data Lake,beyond the Data Warehouse
Data Lake,beyond the Data WarehouseData Lake,beyond the Data Warehouse
Data Lake,beyond the Data Warehouse
Data Science Thailand
 
Ch07 Access Control Fundamentals
Ch07 Access Control FundamentalsCh07 Access Control Fundamentals
Ch07 Access Control Fundamentals
Information Technology
 
ER DIAGRAM & ER MODELING IN DBMS
ER DIAGRAM & ER MODELING IN DBMSER DIAGRAM & ER MODELING IN DBMS
ER DIAGRAM & ER MODELING IN DBMS
ssuser20b618
 
ETL Technologies.pptx
ETL Technologies.pptxETL Technologies.pptx
ETL Technologies.pptx
Gaurav Bhatnagar
 
BloodHound 1.3 - The ACL Attack Path Update - Paranoia17, Oslo
BloodHound 1.3 - The ACL Attack Path Update - Paranoia17, OsloBloodHound 1.3 - The ACL Attack Path Update - Paranoia17, Oslo
BloodHound 1.3 - The ACL Attack Path Update - Paranoia17, Oslo
Andy Robbins
 
RDF and OWL
RDF and OWLRDF and OWL
RDF and OWL
Rachel Lovinger
 
Cyber Kill Chain.pptx
Cyber Kill Chain.pptxCyber Kill Chain.pptx
Cyber Kill Chain.pptx
Vivek Chauhan
 
Big data architectures and the data lake
Big data architectures and the data lakeBig data architectures and the data lake
Big data architectures and the data lake
James Serra
 
Identity and Access Management 101
Identity and Access Management 101Identity and Access Management 101
Identity and Access Management 101
Jerod Brennen
 
Data lineage and observability with Marquez - subsurface 2020
Data lineage and observability with Marquez - subsurface 2020Data lineage and observability with Marquez - subsurface 2020
Data lineage and observability with Marquez - subsurface 2020
Julien Le Dem
 
Threat-Based Adversary Emulation with MITRE ATT&CK
Threat-Based Adversary Emulation with MITRE ATT&CKThreat-Based Adversary Emulation with MITRE ATT&CK
Threat-Based Adversary Emulation with MITRE ATT&CK
Katie Nickels
 
Beyond REST and RPC: Asynchronous Eventing and Messaging Patterns
Beyond REST and RPC: Asynchronous Eventing and Messaging PatternsBeyond REST and RPC: Asynchronous Eventing and Messaging Patterns
Beyond REST and RPC: Asynchronous Eventing and Messaging Patterns
Clemens Vasters
 
Data Warehouse Fundamentals
Data Warehouse FundamentalsData Warehouse Fundamentals
Data Warehouse Fundamentals
Rashmi Bhat
 
Introduction to the Semantic Web
Introduction to the Semantic WebIntroduction to the Semantic Web
Introduction to the Semantic Web
Marin Dimitrov
 
Introduction to OpenID Connect
Introduction to OpenID Connect Introduction to OpenID Connect
Introduction to OpenID Connect
Nat Sakimura
 
Kylin and Druid Presentation
Kylin and Druid PresentationKylin and Druid Presentation
Kylin and Druid Presentation
argonauts007
 
Debunking some “RDF vs. Property Graph” Alternative Facts
Debunking some “RDF vs. Property Graph” Alternative FactsDebunking some “RDF vs. Property Graph” Alternative Facts
Debunking some “RDF vs. Property Graph” Alternative Facts
Neo4j
 
ER DIAGRAM & ER MODELING IN DBMS
ER DIAGRAM & ER MODELING IN DBMSER DIAGRAM & ER MODELING IN DBMS
ER DIAGRAM & ER MODELING IN DBMS
ssuser20b618
 
BloodHound 1.3 - The ACL Attack Path Update - Paranoia17, Oslo
BloodHound 1.3 - The ACL Attack Path Update - Paranoia17, OsloBloodHound 1.3 - The ACL Attack Path Update - Paranoia17, Oslo
BloodHound 1.3 - The ACL Attack Path Update - Paranoia17, Oslo
Andy Robbins
 
Cyber Kill Chain.pptx
Cyber Kill Chain.pptxCyber Kill Chain.pptx
Cyber Kill Chain.pptx
Vivek Chauhan
 
Big data architectures and the data lake
Big data architectures and the data lakeBig data architectures and the data lake
Big data architectures and the data lake
James Serra
 

Viewers also liked (8)

RESTFul Web API Services @ DotNetToscana
RESTFul Web API Services @ DotNetToscanaRESTFul Web API Services @ DotNetToscana
RESTFul Web API Services @ DotNetToscana
Matteo Baglini
 
The Rocky Cloud Road
The Rocky Cloud RoadThe Rocky Cloud Road
The Rocky Cloud Road
Gert Drapers
 
Mendeley Demo @ FCI Assiut
Mendeley Demo @ FCI AssiutMendeley Demo @ FCI Assiut
Mendeley Demo @ FCI Assiut
Mohammed Makhlouf
 
Bottom-Line Web Services
Bottom-Line Web ServicesBottom-Line Web Services
Bottom-Line Web Services
Mohammed Makhlouf
 
Web API 2 Token Based Authentication
Web API 2 Token Based AuthenticationWeb API 2 Token Based Authentication
Web API 2 Token Based Authentication
jeremysbrown
 
Testing and Documenting Pragmatic / RESTful Web API
Testing and Documenting Pragmatic / RESTful Web APITesting and Documenting Pragmatic / RESTful Web API
Testing and Documenting Pragmatic / RESTful Web API
Arul Kumaran
 
淺談RESTful API認證 Token機制使用經驗分享
淺談RESTful API認證 Token機制使用經驗分享淺談RESTful API認證 Token機制使用經驗分享
淺談RESTful API認證 Token機制使用經驗分享
Tun-Yu Chang
 
OData: A Standard API for Data Access
OData: A Standard API for Data AccessOData: A Standard API for Data Access
OData: A Standard API for Data Access
Pat Patterson
 
RESTFul Web API Services @ DotNetToscana
RESTFul Web API Services @ DotNetToscanaRESTFul Web API Services @ DotNetToscana
RESTFul Web API Services @ DotNetToscana
Matteo Baglini
 
The Rocky Cloud Road
The Rocky Cloud RoadThe Rocky Cloud Road
The Rocky Cloud Road
Gert Drapers
 
Web API 2 Token Based Authentication
Web API 2 Token Based AuthenticationWeb API 2 Token Based Authentication
Web API 2 Token Based Authentication
jeremysbrown
 
Testing and Documenting Pragmatic / RESTful Web API
Testing and Documenting Pragmatic / RESTful Web APITesting and Documenting Pragmatic / RESTful Web API
Testing and Documenting Pragmatic / RESTful Web API
Arul Kumaran
 
淺談RESTful API認證 Token機制使用經驗分享
淺談RESTful API認證 Token機制使用經驗分享淺談RESTful API認證 Token機制使用經驗分享
淺談RESTful API認證 Token機制使用經驗分享
Tun-Yu Chang
 
OData: A Standard API for Data Access
OData: A Standard API for Data AccessOData: A Standard API for Data Access
OData: A Standard API for Data Access
Pat Patterson
 
Ad

Similar to Building RESTfull Data Services with WebAPI (20)

Practical OData
Practical ODataPractical OData
Practical OData
Vagif Abilov
 
(ATS6-PLAT04) Query service
(ATS6-PLAT04) Query service (ATS6-PLAT04) Query service
(ATS6-PLAT04) Query service
BIOVIA
 
SOLID Programming with Portable Class Libraries
SOLID Programming with Portable Class LibrariesSOLID Programming with Portable Class Libraries
SOLID Programming with Portable Class Libraries
Vagif Abilov
 
OData Services
OData ServicesOData Services
OData Services
Jovan Popovic
 
MuleSoft London Community February 2020 - MuleSoft and OData
MuleSoft London Community February 2020 - MuleSoft and ODataMuleSoft London Community February 2020 - MuleSoft and OData
MuleSoft London Community February 2020 - MuleSoft and OData
Pace Integration
 
ASP.NET MVC 5 - EF 6 - VS2015
ASP.NET MVC 5 - EF 6 - VS2015ASP.NET MVC 5 - EF 6 - VS2015
ASP.NET MVC 5 - EF 6 - VS2015
Hossein Zahed
 
OData – Super Cola W3
OData – Super Cola W3OData – Super Cola W3
OData – Super Cola W3
Comunidade NetPonto
 
Intro to .NET for Government Developers
Intro to .NET for Government DevelopersIntro to .NET for Government Developers
Intro to .NET for Government Developers
Frank La Vigne
 
ASP.NET Mvc 4 web api
ASP.NET Mvc 4 web apiASP.NET Mvc 4 web api
ASP.NET Mvc 4 web api
Tiago Knoch
 
Expose your data as an api is with oracle rest data services -spoug Madrid
Expose your data as an api is with oracle rest data services -spoug MadridExpose your data as an api is with oracle rest data services -spoug Madrid
Expose your data as an api is with oracle rest data services -spoug Madrid
Vinay Kumar
 
OData support in Cast Iron 7.5.1
OData support in Cast Iron 7.5.1OData support in Cast Iron 7.5.1
OData support in Cast Iron 7.5.1
Sarath Ambadas
 
Denodo Partner Connect: Technical Webinar - Ask Me Anything
Denodo Partner Connect: Technical Webinar - Ask Me AnythingDenodo Partner Connect: Technical Webinar - Ask Me Anything
Denodo Partner Connect: Technical Webinar - Ask Me Anything
Denodo
 
OData: Universal Data Solvent or Clunky Enterprise Goo? (GlueCon 2015)
OData: Universal Data Solvent or Clunky Enterprise Goo? (GlueCon 2015)OData: Universal Data Solvent or Clunky Enterprise Goo? (GlueCon 2015)
OData: Universal Data Solvent or Clunky Enterprise Goo? (GlueCon 2015)
Pat Patterson
 
OLE DB Provider Development - Encapsulating a Service Provider
OLE DB Provider Development - Encapsulating a Service ProviderOLE DB Provider Development - Encapsulating a Service Provider
OLE DB Provider Development - Encapsulating a Service Provider
Arun Seetharaman
 
The Data Web and PLM
The Data Web and PLMThe Data Web and PLM
The Data Web and PLM
Koneksys
 
PI-RDBMS.ppt
PI-RDBMS.pptPI-RDBMS.ppt
PI-RDBMS.ppt
Ajay Gangakhedkar
 
Building Software Backend (Web API)
Building Software Backend (Web API)Building Software Backend (Web API)
Building Software Backend (Web API)
Alexander Goida
 
Web Technologies - forms and actions
Web Technologies -  forms and actionsWeb Technologies -  forms and actions
Web Technologies - forms and actions
Aren Zomorodian
 
OData for iOS developers
OData for iOS developersOData for iOS developers
OData for iOS developers
Glen Gordon
 
Using the Cascade Server Web Service API, by Artur Tomusiak
Using the Cascade Server Web Service API, by Artur TomusiakUsing the Cascade Server Web Service API, by Artur Tomusiak
Using the Cascade Server Web Service API, by Artur Tomusiak
hannonhill
 
(ATS6-PLAT04) Query service
(ATS6-PLAT04) Query service (ATS6-PLAT04) Query service
(ATS6-PLAT04) Query service
BIOVIA
 
SOLID Programming with Portable Class Libraries
SOLID Programming with Portable Class LibrariesSOLID Programming with Portable Class Libraries
SOLID Programming with Portable Class Libraries
Vagif Abilov
 
MuleSoft London Community February 2020 - MuleSoft and OData
MuleSoft London Community February 2020 - MuleSoft and ODataMuleSoft London Community February 2020 - MuleSoft and OData
MuleSoft London Community February 2020 - MuleSoft and OData
Pace Integration
 
ASP.NET MVC 5 - EF 6 - VS2015
ASP.NET MVC 5 - EF 6 - VS2015ASP.NET MVC 5 - EF 6 - VS2015
ASP.NET MVC 5 - EF 6 - VS2015
Hossein Zahed
 
Intro to .NET for Government Developers
Intro to .NET for Government DevelopersIntro to .NET for Government Developers
Intro to .NET for Government Developers
Frank La Vigne
 
ASP.NET Mvc 4 web api
ASP.NET Mvc 4 web apiASP.NET Mvc 4 web api
ASP.NET Mvc 4 web api
Tiago Knoch
 
Expose your data as an api is with oracle rest data services -spoug Madrid
Expose your data as an api is with oracle rest data services -spoug MadridExpose your data as an api is with oracle rest data services -spoug Madrid
Expose your data as an api is with oracle rest data services -spoug Madrid
Vinay Kumar
 
OData support in Cast Iron 7.5.1
OData support in Cast Iron 7.5.1OData support in Cast Iron 7.5.1
OData support in Cast Iron 7.5.1
Sarath Ambadas
 
Denodo Partner Connect: Technical Webinar - Ask Me Anything
Denodo Partner Connect: Technical Webinar - Ask Me AnythingDenodo Partner Connect: Technical Webinar - Ask Me Anything
Denodo Partner Connect: Technical Webinar - Ask Me Anything
Denodo
 
OData: Universal Data Solvent or Clunky Enterprise Goo? (GlueCon 2015)
OData: Universal Data Solvent or Clunky Enterprise Goo? (GlueCon 2015)OData: Universal Data Solvent or Clunky Enterprise Goo? (GlueCon 2015)
OData: Universal Data Solvent or Clunky Enterprise Goo? (GlueCon 2015)
Pat Patterson
 
OLE DB Provider Development - Encapsulating a Service Provider
OLE DB Provider Development - Encapsulating a Service ProviderOLE DB Provider Development - Encapsulating a Service Provider
OLE DB Provider Development - Encapsulating a Service Provider
Arun Seetharaman
 
The Data Web and PLM
The Data Web and PLMThe Data Web and PLM
The Data Web and PLM
Koneksys
 
Building Software Backend (Web API)
Building Software Backend (Web API)Building Software Backend (Web API)
Building Software Backend (Web API)
Alexander Goida
 
Web Technologies - forms and actions
Web Technologies -  forms and actionsWeb Technologies -  forms and actions
Web Technologies - forms and actions
Aren Zomorodian
 
OData for iOS developers
OData for iOS developersOData for iOS developers
OData for iOS developers
Glen Gordon
 
Using the Cascade Server Web Service API, by Artur Tomusiak
Using the Cascade Server Web Service API, by Artur TomusiakUsing the Cascade Server Web Service API, by Artur Tomusiak
Using the Cascade Server Web Service API, by Artur Tomusiak
hannonhill
 
Ad

Recently uploaded (20)

Top 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docxTop 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docx
Portli
 
Societal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainabilitySocietal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainability
Jordi Cabot
 
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
Egor Kaleynik
 
Expand your AI adoption with AgentExchange
Expand your AI adoption with AgentExchangeExpand your AI adoption with AgentExchange
Expand your AI adoption with AgentExchange
Fexle Services Pvt. Ltd.
 
Douwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License codeDouwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License code
aneelaramzan63
 
Meet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Meet the Agents: How AI Is Learning to Think, Plan, and CollaborateMeet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Meet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Maxim Salnikov
 
How can one start with crypto wallet development.pptx
How can one start with crypto wallet development.pptxHow can one start with crypto wallet development.pptx
How can one start with crypto wallet development.pptx
laravinson24
 
Download YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full ActivatedDownload YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full Activated
saniamalik72555
 
The Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdfThe Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdf
drewplanas10
 
Kubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptxKubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptx
CloudScouts
 
Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025
mu394968
 
F-Secure Freedome VPN 2025 Crack Plus Activation New Version
F-Secure Freedome VPN 2025 Crack Plus Activation  New VersionF-Secure Freedome VPN 2025 Crack Plus Activation  New Version
F-Secure Freedome VPN 2025 Crack Plus Activation New Version
saimabibi60507
 
EASEUS Partition Master Crack + License Code
EASEUS Partition Master Crack + License CodeEASEUS Partition Master Crack + License Code
EASEUS Partition Master Crack + License Code
aneelaramzan63
 
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Andre Hora
 
How to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud PerformanceHow to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud Performance
ThousandEyes
 
Download Wondershare Filmora Crack [2025] With Latest
Download Wondershare Filmora Crack [2025] With LatestDownload Wondershare Filmora Crack [2025] With Latest
Download Wondershare Filmora Crack [2025] With Latest
tahirabibi60507
 
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Dele Amefo
 
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
Andre Hora
 
Automation Techniques in RPA - UiPath Certificate
Automation Techniques in RPA - UiPath CertificateAutomation Techniques in RPA - UiPath Certificate
Automation Techniques in RPA - UiPath Certificate
VICTOR MAESTRE RAMIREZ
 
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
ssuserb14185
 
Top 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docxTop 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docx
Portli
 
Societal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainabilitySocietal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainability
Jordi Cabot
 
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
Egor Kaleynik
 
Expand your AI adoption with AgentExchange
Expand your AI adoption with AgentExchangeExpand your AI adoption with AgentExchange
Expand your AI adoption with AgentExchange
Fexle Services Pvt. Ltd.
 
Douwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License codeDouwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License code
aneelaramzan63
 
Meet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Meet the Agents: How AI Is Learning to Think, Plan, and CollaborateMeet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Meet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Maxim Salnikov
 
How can one start with crypto wallet development.pptx
How can one start with crypto wallet development.pptxHow can one start with crypto wallet development.pptx
How can one start with crypto wallet development.pptx
laravinson24
 
Download YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full ActivatedDownload YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full Activated
saniamalik72555
 
The Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdfThe Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdf
drewplanas10
 
Kubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptxKubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptx
CloudScouts
 
Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025
mu394968
 
F-Secure Freedome VPN 2025 Crack Plus Activation New Version
F-Secure Freedome VPN 2025 Crack Plus Activation  New VersionF-Secure Freedome VPN 2025 Crack Plus Activation  New Version
F-Secure Freedome VPN 2025 Crack Plus Activation New Version
saimabibi60507
 
EASEUS Partition Master Crack + License Code
EASEUS Partition Master Crack + License CodeEASEUS Partition Master Crack + License Code
EASEUS Partition Master Crack + License Code
aneelaramzan63
 
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Andre Hora
 
How to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud PerformanceHow to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud Performance
ThousandEyes
 
Download Wondershare Filmora Crack [2025] With Latest
Download Wondershare Filmora Crack [2025] With LatestDownload Wondershare Filmora Crack [2025] With Latest
Download Wondershare Filmora Crack [2025] With Latest
tahirabibi60507
 
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Dele Amefo
 
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
Andre Hora
 
Automation Techniques in RPA - UiPath Certificate
Automation Techniques in RPA - UiPath CertificateAutomation Techniques in RPA - UiPath Certificate
Automation Techniques in RPA - UiPath Certificate
VICTOR MAESTRE RAMIREZ
 
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
ssuserb14185
 

Building RESTfull Data Services with WebAPI

  • 1. Building RESTfull Data Services with WebAPI Gert Drapers (#DataDude) Principle Software Design Engineer
  • 4. OData Value Proposition • Problem Statement: • There is no consistent data interoperability protocol for addressing and manipulating enterprise data across various devices and platforms • Value Proposition: • OData enables consistent REST-based data access from a variety of back ends including relational databases, file systems, content management systems, and traditional Web sites • OData builds on widely-accepted standards like HTTP, JSON, AtomPub, and URIs to address and access data
  • 5. What OData Is and Is Not? • What OData Is: • Easy, consistent data access via HTTP endpoints • REST-based data operations: CRUD, Filtering, Sorting, Paging, Custom Operations, Delta, etc. • Service centric data definition, operation and annotation • Schematized and schema-less data sets • Broadly accepted JSON/ATOM format on the wire • What OData Is Not: • Not to replace native or direct data access interface, e.g. ODBC/TDS for SQL • Not to replace highly specialized BI technologies like XMLA
  • 6. OData Status • OData v4 to be standardized in Feb. in OASIS • http://docs.oasis-open.org/odata/new-in-odata/v4.0/cn01/new-in-odata-v4.0- cn01.html • ODL 6.2 • http://blogs.msdn.com/b/odatateam/archive/2014/04/14/odl-6-2-release- announcement.aspx • Web API OData 6.1 • http://blogs.msdn.com/b/odatateam/archive/2014/03/21/odata-6-1-and-odata- client-6-1-are-now-shipped.aspx • WCF Data Services moved to OSS • http://blogs.msdn.com/b/odatateam/archive/2014/03/27/future-direction-of-wcf- data-services.aspx http://odata.org/
  • 8. Technology Basics Client Server OData Service OData Protocol Library OData Data Model Library Data Source Technology .NET OData Data Model Library Microsoft.odata.edm.dll OData Protocol Library Microsoft.odata.core.dll OData Service WCF Data Service/ Web API/ User’s own service OData Client Library Microsoft.odata.client.dll Code Generator T4 / item template OData Protocol Library OData Data Model Library OData Client Library OData Protocol Library OData Data Model Library
  • 9. How to build client to consume OData Business Logic Dev OData Service Metadata request Use Code Generatror to generate client class Client Application Account account = TestClientContext.Accounts.Where(account => account.AccountID == 110).Single(); account.Country=”US”; TestClientContext.UpdateObject(account); TestClientContext.SaveChanges(); Code Files(Account.cs/ TestClientContext.cs) Microsoft.odata.client.dll The client dll will generate the request based on the property change on the Account object Get http://localhost:8080/OData/Accounts(110) Patch http://localhost:8080/OData/Accounts(110)
  • 10. What’s in Microsoft.OData.Client.dll •Deserialize/Serialize OData payload • Using API provided by Microsoft.OData.Core.dll •Request Generator/LINQ to URL •Entity Tracker •Batch support
  • 11. OData Data Model Library • OData is based on the Entity Data Model (EDM): • EDM presents information in a way which is familiar to many developers dealing with data today making it easy for them to understand and use. • Data provider can use OData Data Model Library to create the EDM model of the data they want to expose. The client can consume the data based on the EDM model that exposed by service and figure out the relationship between entities.
  • 12. EDM Example Entity Container Entity set (Categories) Category CategoryId Product Entity set (Products) Product ProductId Description Navigation property binding
  • 13. EDM Example – Cont. • <?xml version="1.0" encoding="utf-8"?> <edmx:Edmx Version="4.0" xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx"> <edmx:DataServices> <Schema Namespace="Microsoft.Test.OData.Services.ODataWCFService" xmlns="http://docs.oasis-open.org/odata/ns/edm"> <EntityType Name="Category"> <Key> <PropertyRef Name="CategoryId" /> </Key> <Property Name="CategoryId" Type="Edm.String" Nullable="false" /> <Property Name="Name" Type="Edm.String" Nullable="false" /> <NavigationProperty Name="Product" Type="Microsoft.Test.OData.Services.ODataWCFService.Product" Nullable="false" /> </EntityType> <EntityType Name="Product"> <Key> <PropertyRef Name="ProductId" /> </Key> <Property Name="ProductId" Type="Edm.String" Nullable="false" /> <Property Name="Name" Type="Edm.String" Nullable="false" /> <Property Name="Desciption" Type="Edm.String" Nullable="false" /> </EntityType> <EntityContainer Name="ServiceContainer"> <EntitySet Name="Categories" EntityType="Microsoft.Test.OData.Services.ODataWCFService.Category"> <NavigationPropertyBinding Path="Product" Target="Products" /> </EntitySet> <EntitySet Name="Products" EntityType="Microsoft.Test.OData.Services.ODataWCFService.Product"> </EntitySet> </EntityContainer> </Schema> </edmx:DataServices> </edmx:Edmx>
  • 14. EDM Example – Cont. • Category Entity: • http://localhost/odata/Categories(1) • Product under this category • http://localhost/odata/Categories(1)/Product • Through navigation binding defined in the Categories and the navigation property defined in the Category, target entity set Products can be found • Entity product can be located in entity set Products
  • 15. OData Protocol Library • Deserialize/Serialize payload • JSON • Full metadata level – { – "@odata.context":"http://localhost:50671/ODataService.svc/OData/$metadata#Products/$entity", – "@odata.id":"http://localhost:50671/ODataService.svc/OData/Products(5)", – "@odata.editLink":"http://localhost:50671/ODataService.svc/OData/Products(5)", – "ProductID":5, – "Name":"Cheetos", – "Description":"Cheese curl" – } • Minimal metadata level – Writer only writes the necessary metadata – Reader will auto complete the metadata during reading – { – "@odata.context":"http://localhost:50671/ODataService.svc/OData/$metadata#Products/$entity", – "ProductID":5, – "Name":"Cheetos", – "Description":"Cheese curl" – } • No metadata level – Data only – { – "ProductID":5, – "Name":"Cheetos", – "Description":"Cheese curl" – } • ATOM
  • 16. OData Protocol Library • Targeting the target resource based on the URI • $top=n: Returns only the first n entities in an entity set (or in Atom terms, the first n entries in a feed) • $skip=n: Skips the first n entities in an entity set. Using this option lets a client retrieve a series of distinct pages on subsequent requests • $format: Determines whether data should be returned in JSON or the XML- based Atom/AtomPub format • $orderby=: Orders results, in ascending or descending order, by the value of one or more properties in those results • $filter=: Returns only entities that match the specified expression • $select=: Returns only the specified properties in an entity • $expand=: Returns the navigation property in an entity URI Parser
  • 17. OData Protocol Library – Cont. • http://services.odata.org/V3/Northwind/Northwind.svc/Order_Details?$top=5 &$select=OrderID,ProductID&$skip=1&$filter=OrderID gt 10248 • Parsed result of request URI as an ODataUri object • TopCount • SkipCount • SelectExpandClause • List<SelectedItem> – PathSelectionItem » Path=OrderID – PathSelectionItem » Path=ProductID • FilterClause • FilterExpression
  • 19. WebApi.OData: Overview •An OData service library •Build upon a lightweight http stack •Be part of ASP.NET RESTful framework •Selective query ability •Another option to build OData service
  • 20. Simple way to build OData Service •No need to know the details of OData Protocol •POCO (Plain Old CLR Object) model •ODataConventionModelBuilder: 3 lines of code var builder = new ODataConventionModelBuilder(); builder.EntitySet<Product>("Products"); IEdmModel model = builder.GetEdmModel(); •ODataController: VS2013 scaffolding
  • 21. Web API OData Architecture Diagram Message Handler Controller Selection ODataController Action Action Filter MapODataRoute*GetEdmModelModel builderEdm Lib Spatial Lib Formatter OData Lib Serialize Deserialize Query Entity Framework DbContext DbSet Action Filter Formatter Model Binder QueryOption Action Selection Type system HttpRequestMessage HttpResponseMessage
  • 22. Components • Model builder • ODataModelBuilder • ODataConventionModelBuilder (a 3 lines of code approach) • Query • ODL Semantic AST -> LINQ Expression (IQueryable) -> LINQ to * (Entities, Objects…) • Routing • Conventional • Attribute route • Formatter • Serializer: CLR type / typeless -> OData*Value • Deserializer: OData*Value -> CLR type / typeless
  • 23. Routing Examples // Metadata routes to support $metadata and code generation in the // WCF Data Service client. configuration.Routes.MapHttpRoute( ODataRouteNames.Metadata, "$metadata", new { Controller = "ODataMetadata", Action = "GetMetadata" } ); configuration.Routes.MapHttpRoute( ODataRouteNames.ServiceDocument, "", new { Controller = "ODataMetadata", Action = "GetServiceDocument" } );
  • 24. Routing Examples… // Relationship routes (notice the parameters is {type}Id not id, // this avoids colliding with GetById(id)). // This code handles requests like ~/ProductFamilies(1)/Products configuration.Routes.MapHttpRoute( ODataRouteNames.PropertyNavigation, "{controller}({parentId})/{navigationProperty}"); // Route for manipulating links, the code allows people to create and // delete relationships between entities configuration.Routes.MapHttpRoute( ODataRouteNames.Link, "{controller}({id})/$links/{navigationProperty}");
  • 25. Routing Examples… // Routes for urls both producing and handling URLs // like: ~/Product(1), ~/Products() and ~/Products configuration.Routes.MapHttpRoute( ODataRouteNames.GetById, "{controller}({id})"); configuration.Routes.MapHttpRoute( ODataRouteNames.DefaultWithParentheses, "{controller}()"); configuration.Routes.MapHttpRoute( ODataRouteNames.Default, "{controller}");
  • 26. Model Builder • ODataConventionModelBuilder • Use reflection and conventions to generate an Edm model • Reflection • Type • PropertyInfo • MethodInfo • Conventions • AttributeConvention • AttributeEdmTypeConvention: [DataContract] • AttributeEdmPropertyConvention: • [Key] • [DataMember] • [IgnoreDataMember] • [Required] • [ConcurrencyCheck]…
  • 27. ODataModelBuilder • Take full control var builder = new ODataModelBuilder(); var products = builder.EntitySet<Product>("Products"); var product = products.EntityType; product.HasKey(p => p.ID); product.Property(p => p.Name); var rate = product.Action("Rate"); rate.Parameter<int>("Rating"); rate.Returns<double>(); • EntitySetConfiguration • EntityTypeConfiguration • PropertyConfiguration • ProcedureConfiguration • ParameterConfiguration
  • 28. Query • /Products/?$filter=Name eq ‘abc’ • One key differentiator than other Web API implementations • QueryableAttribute [Queryable] public IQueryable<Product> GetProducts() { return db.Products; } • => ODataQueryOptions public IEnumerable<Product> GetProducts(ODataQueryOptions options) { return options.ApplyTo(db.Products) as IEnumerable<Product>; } • FilterQueryOption -> FilterBinder: • Convert OData AST FilterClause’s QueryNode to Linq Expression
  • 29. Routing • IODataRoutingConvention • string SelectController(ODataPath odataPath, HttpRequestMessage request); • string SelectAction(ODataPath odataPath, HttpControllerContext controllerContext, ILookup<string, HttpActionDescriptor> actionMap); • Convention based route: • EntitySetRoutingConvention • EntityRoutingConvention • ActionRoutingConvention • FunctionRoutingConvention • NavigationRoutingConvention • PropertyRoutingConvention • Attribute based route: • AttributeRoutingConvention • ODataRouteAttribute • MapODataRoute
  • 30. Formatter • Why does webapi.odata need to handle serialization and deserialization? • ODL handles OData object model to Payload • Web API handles POCO to OData OM • The hook: [ODataFormatting] public abstract class ODataController : ApiController • ODataFormattingAttribute • Inserts the ODataMediaTypeFormatters into the HttpControllerSettings.Formatters collection. • Attaches the request to the OData formatter instance. • ODataMediaTypeFormatter.Create() • ODataSerializerProvider / ODataDeserializerProvider • OData*Serializer / OData*Deserializer
  • 31. Demo Build an OData Web API application
  • 32. Laat ons weten wat u vindt van deze sessie! Vul de evaluatie in via www.techdaysapp.nl en maak kans op een van de 20 prijzen*. Prijswinnaars worden bekend gemaakt via Twitter (#TechDaysNL). Gebruik hiervoor de code op uw badge. Let us know how you feel about this session! Give your feedback via www.techdaysapp.nl and possibly win one of the 20 prices*. Winners will be announced via Twitter (#TechDaysNL). Use your personal code on your badge. * Over de uitslag kan niet worden gecorrespondeerd, prijzen zijn voorbeelden – All results are final, prices are examples