SlideShare ist ein Scribd-Unternehmen logo
1 von 44
Vagif Abilov
Miles AS
vagif.abilov@gmail.com
@ooobject
github: object
http://bloggingabout.net/blogs/vagif/
 OData  and REST
 WCF Data Services
 OData feed in 5 minutes: EF + MS SQL
 The power of ObjectContext
 Using reflection provider
 Using custom providers and NoSQL
 Extending OData services
 Performance and diagnostics
 A song about OData
Are you familiar with OData?

 Have you used OData in your projects?

Do you have components on your machine
     that use OData communication?
 The Open Data Protocol (OData) is a Web
  protocol for querying and updating data
 Consumers query a datasource over HTTP
  and get results back in formats like
  AtomPub, JSON or plain XML
 OData follows many of the principles of
  REST
Querying NuGet feed with LINQPad

Importing data from OData feed into
 Microsoft Excel using PowerPivot
 Command   content specified in URIs
 Use of HTTP verbs (GET, POST, PUT,
  DELETE)
 Use of HTTP status codes
 Response sent as XML (AtomPub) or
  JSON
 Related content specified using link
  elements
Hypermedia


  HTTP


   URI
Method   Safe   Idempotent
GET      Yes       Yes
POST     No        No
PUT      No        Yes
DELETE   No        Yes
http://localhost:50555/InMemory.svc/
Customers('ALFKI')

http://localhost:50555/InMemory.svc/
Customers()?$filter=CompanyName eq
'Alfreds Futterkiste„

http://localhost:50555/InMemory.svc/
Customers()?$expand=Orders
http://localhost.:50555/InMemory.svc/
Customers
<entry term="Northwind.InMemory.Customers" />
 <content type="application/xml">
  <m:properties>
    <d:CompanyName>My
Company</d:CompanyName>
    <d:CustomerID>TEMP</d:CustomerID>
  </m:properties>
 </content>
</entry>
http://localhost.:50555/InMemory.svc/
Customers(„TEMP')
<entry term="Northwind.InMemory.Customers" />
 <content type="application/xml">
  <m:properties>
    <d:CompanyName>My New
Company</d:CompanyName>
    <d:CustomerID>TEMP</d:CustomerID>
  </m:properties>
 </content>
</entry>
http://localhost.:50555/InMemory.svc/
Customers(„TEMP')
Request: a company with non-existing
CompanyName

Response: an empty collection

Request: a company with non-existing
CompanyID

Response: 404 Not Found
var ctx = new NorthwindContext("http://localhost.:50555/InMemory.svc");
ctx.IgnoreResourceNotFoundException = true;
var customers =
         from c in ctx.Customers
         where c.CustomerID == "XYZ"
         select c;
 Formerly ADO.NET    Data Services
 Codename “Astoria”
 OData provider library for .NET
 Not to be confused with WCF RIA Services
  designed specifically for end-to-end
  Silverlight and ASP.NET applications
 Using Entity Framework provider
  • EF model first+ MS SQL – trivial
  • EF code first, different DB vendors – easy
 Using reflection provider
  • Any context exposing a set of IQueryable
    properties – easy
  • Implementing IUpdatable for updatable OData
    feeds – easy
 Using custom provider
  • OData provider toolkit usually helps – still complex
public class EntityFrameworkModelFirstMsSql :
DataService<NorthwindMsSqlContext>
{
  public static void InitializeService(DataServiceConfiguration config)
  {
     config.SetEntitySetAccessRule("*", EntitySetRights.All);
     config.SetServiceOperationAccessRule("*", ServiceOperationRights.All);
     config.DataServiceBehavior.MaxProtocolVersion =
DataServiceProtocolVersion.V2;
  }

    protected override NorthwindMsSqlContext CreateDataSource()
    {
      return new NorthwindMsSqlContext(/* connection string */);
    }
}
 As simple as with MS SQL assuming EF
  provider for the respective vendor is
  available
 Proven choice: Devart dotConnect product
  family:
  • Oracle
  • MySQL
  • PostgreSQL
  • SQLite
 Not supported by tools
 EDMX is just an XML file with 3 main
  sections:
  • Conceptual model (CSDL)
  • Storage model (SSDL)
  • Mapping (MSL)
 You   can author your own EF model:
  • Support for n database vendors
  • 2n + 1 XML sections (1 CSDL + n SSDL + n MSL)
 DbContext   class, wraps ObjectContext
 Model is generated from entities
 Database can be generated from the
  model
 Convention over configuration reduces
  configuration code to bare minimum
 No more trick to share conceptual model
  between databases from different vendors
public class NorthwindContextBase : DbContext
{
  public ObjectContext ObjectContext
  {
     get { return (this as IObjectContextAdapter).ObjectContext; }
  }
}

public class EntityFrameworkCodeFirstMsSql : DataService<ObjectContext>
{
  protected override ObjectContext CreateDataSource()
  {
     var ctx = new NorthwindContext("NorthwindContext.EF.CF.MsSql");
     return ctx.ObjectContext;
  }
}
 Suitable for most of scenarios with static
  resource set information (schema known
  at compile time)
 Resource sets exposed as IQueryable<T>
  properties of the context class
 DataServiceKey attribute specifies entity
  key
 Optional support for IUpdatable
OData feed exposing
in-memory data collection

  OData feed using
 NHibernate to access
  MS SQL database
 Entity Framework provider is the quickest
  way to add OData feed on the top of a
  popular SQL database
 Reflection provider covers most of other
  scenarios when the data schema is known
  up-front
 Custom provider is needed when the
  schema is discovered at runtime or data
  don‟t have fixed types
 If the content of NoSQL database is known
  at compile time, reflection provider can be
  used
 If the content of NoSQL database is
  divided into collections of fixed types, the
  resource sets can be built at runtime
 If the content is untyped, OData feed can
  still be built using open types
Creating OData feed for MongoDB
    using WCF Data Services
   and OData Provider Toolkit
 OData   data model supports open types for
  Entries. An entry of an open type may
  have extra properties (dynamic properties)
  in addition to those statically declared in
  metadata
 WCF Data Services framework takes care
  of transforming the incoming requests into
  an expression tree. Custom code is
  responsible for evaluation expression tree
  against the data store
 Custom   service operations can only use
  HTTP GET and POST
 Generated client context code does not
  include custom service operations – it has
  to be added manually
 Default webHttpBinding settings may not
  be sufficient for large payload
  (send/receiveTimeout, maxBufferSize and
  maxStringContentLength often need to be
  increased)
[WebInvoke(Method = "POST")]
public void DeleteProductsByNamePattern(string namePattern)
{
  this.CurrentDataSource.ExecuteStoreCommand(
         string.Format("DELETE FROM Products WHERE
         ProductName LIKE '{0}%'", namePattern));
}
public void DeleteProductsByNamePattern(string namePattern)
{
  HttpWebRequest request = (HttpWebRequest)WebRequest.Create(
     string.Format("{0}/DeleteProductsByNamePattern?namePattern={1}",
               this.BaseUri, namePattern));
  request.Method = "POST";
  request.Accept = "application/atom+xml,application/xml";
  request.ContentType = "application/atom+xml";
  request.ContentLength = 0;
  HttpWebResponse response = (HttpWebResponse)request.GetResponse();
}
 OData  design goal is to provide data
  publishing protocol for services, not for
  low-level components
 Don‟t use OData to implement cascaded
  updates and deletes of large number of
  dependent entities
 Understand the difference between client-
  side and server-side operations
 LINQPad   (LINQ to OData)
 Fiddler
 RedGate   .NET Reflector Pro (to step-in to
  WCF Data Services code)
 Oren Eini‟s profilers (EF Profiler,
  NHibernate Profiler)
 Elmah logging framework (install it using
  NuGet, it will update your web.config)
 Don‟t reinvent the wheel, don‟t come with
  your own standards
 Consider OData to expose data sources
  on the Web
 Don‟t treat OData as a SQL database
  publisher
 Writing OData feeds is easy
 Code   examples for this presentation:
  https://github.com/object/
  NorthwindOData
 Open Data Protocol:
  http://www.odata.org/
  http://www.odata.org/mailing-list
 WCF Data Services forum:
  http://social.msdn.microsoft.com/Forums/e
  n/adodotnetdataservices/
 WCF    Data Services Toolkit:
  http://wcfdstoolkit.codeplex.com/
 Microsoft WCF Data Services March 2011
  CTP 2 for .NET Framework 4 and
  Silverlight 4:
  http://www.microsoft.com/downloads/en/de
  tails.aspx?FamilyID=60fb0117-8cea-4359-
  b392-6b04cdc821be
OData!
(Lennon – McCartney)
OData! Please relieve me
AtomPub is what I‟m gonna need
Believe me when I tell you:
AtomPub is what I‟m gonna need
OData! Please relieve me
JSON‟s what I want in JavaScript
Believe me when I tell you:
JSON‟s what I want in JavaScript
When you told me:
“Internal error 500”
Oh well you know,
I nearly broke down and cried

When you told me:
“Internal error 501”
Oh well you know,
I nearly broke down and died
OData! Please relieve me
I want to live a RESTful life
Believe me when I tell you:
I want to live a RESTful life
 Vagif  Abilov
 Miles AS
 vagif.abilov@gmail.com
 @ooobject
 github: object
 http://bloggingabout.net/blogs/vagif/

Weitere ähnliche Inhalte

Was ist angesagt?

OData and SharePoint
OData and SharePointOData and SharePoint
OData and SharePoint
Sanjay Patel
 
Modern REST APIs for Enterprise Databases - OData
Modern REST APIs for Enterprise Databases - ODataModern REST APIs for Enterprise Databases - OData
Modern REST APIs for Enterprise Databases - OData
Nishanth Kadiyala
 
Deploying RDF Linked Data via Virtuoso Universal Server
Deploying RDF Linked Data via Virtuoso Universal ServerDeploying RDF Linked Data via Virtuoso Universal Server
Deploying RDF Linked Data via Virtuoso Universal Server
rumito
 

Was ist angesagt? (20)

OData and SharePoint
OData and SharePointOData and SharePoint
OData and SharePoint
 
SAP ODATA Overview & Guidelines
SAP ODATA Overview & GuidelinesSAP ODATA Overview & Guidelines
SAP ODATA Overview & Guidelines
 
UI5Con presentation on UI5 OData V4 Model
UI5Con presentation on UI5 OData V4 ModelUI5Con presentation on UI5 OData V4 Model
UI5Con presentation on UI5 OData V4 Model
 
Odata V4 : The New way to REST for Your Applications
Odata V4 : The New way to REST for Your Applications Odata V4 : The New way to REST for Your Applications
Odata V4 : The New way to REST for Your Applications
 
OData - The Universal REST API
OData - The Universal REST APIOData - The Universal REST API
OData - The Universal REST API
 
OData Fundamental
OData FundamentalOData Fundamental
OData Fundamental
 
Building RESTful Applications with OData
Building RESTful Applications with ODataBuilding RESTful Applications with OData
Building RESTful Applications with OData
 
Open Data Protocol (OData)
Open Data Protocol (OData)Open Data Protocol (OData)
Open Data Protocol (OData)
 
Modern REST APIs for Enterprise Databases - OData
Modern REST APIs for Enterprise Databases - ODataModern REST APIs for Enterprise Databases - OData
Modern REST APIs for Enterprise Databases - OData
 
OData, External objects & Lightning Connect
OData, External objects & Lightning ConnectOData, External objects & Lightning Connect
OData, External objects & Lightning Connect
 
OData Services
OData ServicesOData Services
OData Services
 
OData for iOS developers
OData for iOS developersOData for iOS developers
OData for iOS developers
 
Introduction to External Objects and the OData Connector
Introduction to External Objects and the OData ConnectorIntroduction to External Objects and the OData Connector
Introduction to External Objects and the OData Connector
 
Deploying RDF Linked Data via Virtuoso Universal Server
Deploying RDF Linked Data via Virtuoso Universal ServerDeploying RDF Linked Data via Virtuoso Universal Server
Deploying RDF Linked Data via Virtuoso Universal Server
 
Odata - Open Data Protocol
Odata - Open Data ProtocolOdata - Open Data Protocol
Odata - Open Data Protocol
 
OData, Open Data Protocol. A brief introduction
OData, Open Data Protocol. A brief introductionOData, Open Data Protocol. A brief introduction
OData, Open Data Protocol. A brief introduction
 
JSON and the Oracle Database
JSON and the Oracle DatabaseJSON and the Oracle Database
JSON and the Oracle Database
 
JAX-RS 2.0: RESTful Web Services
JAX-RS 2.0: RESTful Web ServicesJAX-RS 2.0: RESTful Web Services
JAX-RS 2.0: RESTful Web Services
 
APEX Office Hours Interactive Grid Deep Dive
APEX Office Hours Interactive Grid Deep DiveAPEX Office Hours Interactive Grid Deep Dive
APEX Office Hours Interactive Grid Deep Dive
 
Solving Real Problems Using Linked Data
Solving Real Problems Using Linked DataSolving Real Problems Using Linked Data
Solving Real Problems Using Linked Data
 

Andere mochten auch

Odata introduction-slides
Odata introduction-slidesOdata introduction-slides
Odata introduction-slides
MasterCode.vn
 

Andere mochten auch (16)

Introduction to SAP Gateway and OData
Introduction to SAP Gateway and ODataIntroduction to SAP Gateway and OData
Introduction to SAP Gateway and OData
 
Odata
OdataOdata
Odata
 
OData and the future of business objects universes
OData and the future of business objects universesOData and the future of business objects universes
OData and the future of business objects universes
 
Odata introduction-slides
Odata introduction-slidesOdata introduction-slides
Odata introduction-slides
 
OData Hackathon Challenge
OData Hackathon ChallengeOData Hackathon Challenge
OData Hackathon Challenge
 
Setting Your Data Free With OData
Setting Your Data Free With ODataSetting Your Data Free With OData
Setting Your Data Free With OData
 
Consuming Data From Many Platforms: The Benefits of OData - St. Louis Day of ...
Consuming Data From Many Platforms: The Benefits of OData - St. Louis Day of ...Consuming Data From Many Platforms: The Benefits of OData - St. Louis Day of ...
Consuming Data From Many Platforms: The Benefits of OData - St. Louis Day of ...
 
Moni jaiswal resume
Moni jaiswal resumeMoni jaiswal resume
Moni jaiswal resume
 
OData
ODataOData
OData
 
jQuery and OData - Perfect Together
jQuery and OData - Perfect TogetherjQuery and OData - Perfect Together
jQuery and OData - Perfect Together
 
Develop Netflix Movie Search App using jQuery, OData, JSONP and Netflix Techn...
Develop Netflix Movie Search App using jQuery, OData, JSONP and Netflix Techn...Develop Netflix Movie Search App using jQuery, OData, JSONP and Netflix Techn...
Develop Netflix Movie Search App using jQuery, OData, JSONP and Netflix Techn...
 
20120306 meetup scrum
20120306 meetup scrum20120306 meetup scrum
20120306 meetup scrum
 
Daniel Ridder How to RESTify your ABAP backend
Daniel Ridder How to RESTify your ABAP backendDaniel Ridder How to RESTify your ABAP backend
Daniel Ridder How to RESTify your ABAP backend
 
Breaking down data silos with OData
Breaking down data silos with ODataBreaking down data silos with OData
Breaking down data silos with OData
 
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)
 
Sap abap on hana
Sap abap on hanaSap abap on hana
Sap abap on hana
 

Ähnlich wie Practical OData

Ado.Net Data Services (Astoria)
Ado.Net Data Services (Astoria)Ado.Net Data Services (Astoria)
Ado.Net Data Services (Astoria)
Igor Moochnick
 
Web Technologies - forms and actions
Web Technologies -  forms and actionsWeb Technologies -  forms and actions
Web Technologies - forms and actions
Aren Zomorodian
 
What's New for Data?
What's New for Data?What's New for Data?
What's New for Data?
ukdpe
 
ADO .NET by Sonu Vishwakarma
ADO .NET by Sonu VishwakarmaADO .NET by Sonu Vishwakarma
ADO .NET by Sonu Vishwakarma
Sonu Vishwakarma
 
Creating Flexible Data Services For Enterprise Soa With Wso2 Data Services
Creating Flexible Data Services For Enterprise Soa With Wso2 Data ServicesCreating Flexible Data Services For Enterprise Soa With Wso2 Data Services
Creating Flexible Data Services For Enterprise Soa With Wso2 Data Services
sumedha.r
 
Time for a REST - .NET Framework v3.5 & RESTful Web Services
Time for a REST - .NET Framework v3.5 & RESTful Web ServicesTime for a REST - .NET Framework v3.5 & RESTful Web Services
Time for a REST - .NET Framework v3.5 & RESTful Web Services
ukdpe
 

Ähnlich wie Practical OData (20)

ADO.NET Data Services
ADO.NET Data ServicesADO.NET Data Services
ADO.NET Data Services
 
Ado.Net Data Services (Astoria)
Ado.Net Data Services (Astoria)Ado.Net Data Services (Astoria)
Ado.Net Data Services (Astoria)
 
Windows Azure and a little SQL Data Services
Windows Azure and a little SQL Data ServicesWindows Azure and a little SQL Data Services
Windows Azure and a little SQL Data Services
 
Building nTier Applications with Entity Framework Services (Part 2)
Building nTier Applications with Entity Framework Services (Part 2)Building nTier Applications with Entity Framework Services (Part 2)
Building nTier Applications with Entity Framework Services (Part 2)
 
Building nTier Applications with Entity Framework Services (Part 2)
Building nTier Applications with Entity Framework Services (Part 2)Building nTier Applications with Entity Framework Services (Part 2)
Building nTier Applications with Entity Framework Services (Part 2)
 
Web Technologies - forms and actions
Web Technologies -  forms and actionsWeb Technologies -  forms and actions
Web Technologies - forms and actions
 
Data access
Data accessData access
Data access
 
Building RESTfull Data Services with WebAPI
Building RESTfull Data Services with WebAPIBuilding RESTfull Data Services with WebAPI
Building RESTfull Data Services with WebAPI
 
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
 
What's New for Data?
What's New for Data?What's New for Data?
What's New for Data?
 
Wcf data services
Wcf data servicesWcf data services
Wcf data services
 
ADO .NET by Sonu Vishwakarma
ADO .NET by Sonu VishwakarmaADO .NET by Sonu Vishwakarma
ADO .NET by Sonu Vishwakarma
 
Creating Flexible Data Services For Enterprise Soa With Wso2 Data Services
Creating Flexible Data Services For Enterprise Soa With Wso2 Data ServicesCreating Flexible Data Services For Enterprise Soa With Wso2 Data Services
Creating Flexible Data Services For Enterprise Soa With Wso2 Data Services
 
PPT
PPTPPT
PPT
 
Time for a REST - .NET Framework v3.5 & RESTful Web Services
Time for a REST - .NET Framework v3.5 & RESTful Web ServicesTime for a REST - .NET Framework v3.5 & RESTful Web Services
Time for a REST - .NET Framework v3.5 & RESTful Web Services
 
70487.pdf
70487.pdf70487.pdf
70487.pdf
 
Scaling asp.net websites to millions of users
Scaling asp.net websites to millions of usersScaling asp.net websites to millions of users
Scaling asp.net websites to millions of users
 
ADO.NET by ASP.NET Development Company in india
ADO.NET by ASP.NET  Development Company in indiaADO.NET by ASP.NET  Development Company in india
ADO.NET by ASP.NET Development Company in india
 
Real-Time Web Applications with ASP.NET WebAPI and SignalR
Real-Time Web Applications with ASP.NET WebAPI and SignalRReal-Time Web Applications with ASP.NET WebAPI and SignalR
Real-Time Web Applications with ASP.NET WebAPI and SignalR
 
Olap
OlapOlap
Olap
 

Mehr von Vagif Abilov

Mehr von Vagif Abilov (8)

А нам-то зачем функциональное программирование?
А нам-то зачем функциональное программирование?А нам-то зачем функциональное программирование?
А нам-то зачем функциональное программирование?
 
Cross-platform Mobile Development using Portable Class Libraries
Cross-platform Mobile Development using Portable Class LibrariesCross-platform Mobile Development using Portable Class Libraries
Cross-platform Mobile Development using Portable Class Libraries
 
Staying Close to Experts with Executable Specifications
Staying Close to Experts with Executable SpecificationsStaying Close to Experts with Executable Specifications
Staying Close to Experts with Executable Specifications
 
SOLID Programming with Portable Class Libraries
SOLID Programming with Portable Class LibrariesSOLID Programming with Portable Class Libraries
SOLID Programming with Portable Class Libraries
 
Typed? Dynamic? Both! Cross-platform DSLs in C#
Typed? Dynamic? Both! Cross-platform DSLs in C#Typed? Dynamic? Both! Cross-platform DSLs in C#
Typed? Dynamic? Both! Cross-platform DSLs in C#
 
Путь к чистому и компактному коду исполняемых спецификаций
Путь к чистому и компактному коду исполняемых спецификацийПуть к чистому и компактному коду исполняемых спецификаций
Путь к чистому и компактному коду исполняемых спецификаций
 
F# in Action: Playing Functional Conway's Game of Life
F# in Action: Playing Functional Conway's Game of LifeF# in Action: Playing Functional Conway's Game of Life
F# in Action: Playing Functional Conway's Game of Life
 
Executable Specifications in Action
Executable Specifications in ActionExecutable Specifications in Action
Executable Specifications in Action
 

Kürzlich hochgeladen

Famous Kala Jadu, Black magic expert in UK and Kala ilam expert in Saudi Arab...
Famous Kala Jadu, Black magic expert in UK and Kala ilam expert in Saudi Arab...Famous Kala Jadu, Black magic expert in UK and Kala ilam expert in Saudi Arab...
Famous Kala Jadu, Black magic expert in UK and Kala ilam expert in Saudi Arab...
baharayali
 
Verified Amil baba in Pakistan Amil baba in Islamabad Famous Amil baba in Ger...
Verified Amil baba in Pakistan Amil baba in Islamabad Famous Amil baba in Ger...Verified Amil baba in Pakistan Amil baba in Islamabad Famous Amil baba in Ger...
Verified Amil baba in Pakistan Amil baba in Islamabad Famous Amil baba in Ger...
Amil Baba Naveed Bangali
 
Famous Kala Jadu, Black magic specialist in Rawalpindi and Bangali Amil baba ...
Famous Kala Jadu, Black magic specialist in Rawalpindi and Bangali Amil baba ...Famous Kala Jadu, Black magic specialist in Rawalpindi and Bangali Amil baba ...
Famous Kala Jadu, Black magic specialist in Rawalpindi and Bangali Amil baba ...
baharayali
 
Popular Kala Jadu, Black magic expert in Karachi and Kala jadu expert in Laho...
Popular Kala Jadu, Black magic expert in Karachi and Kala jadu expert in Laho...Popular Kala Jadu, Black magic expert in Karachi and Kala jadu expert in Laho...
Popular Kala Jadu, Black magic expert in Karachi and Kala jadu expert in Laho...
baharayali
 
Popular Kala Jadu, Black magic specialist in Sialkot and Kala ilam specialist...
Popular Kala Jadu, Black magic specialist in Sialkot and Kala ilam specialist...Popular Kala Jadu, Black magic specialist in Sialkot and Kala ilam specialist...
Popular Kala Jadu, Black magic specialist in Sialkot and Kala ilam specialist...
baharayali
 
Famous Kala Jadu, Black magic specialist in Lahore and Kala ilam expert in ka...
Famous Kala Jadu, Black magic specialist in Lahore and Kala ilam expert in ka...Famous Kala Jadu, Black magic specialist in Lahore and Kala ilam expert in ka...
Famous Kala Jadu, Black magic specialist in Lahore and Kala ilam expert in ka...
baharayali
 
Authentic Black magic, Kala ilam expert in UAE and Kala ilam specialist in S...
Authentic Black magic, Kala ilam expert in UAE  and Kala ilam specialist in S...Authentic Black magic, Kala ilam expert in UAE  and Kala ilam specialist in S...
Authentic Black magic, Kala ilam expert in UAE and Kala ilam specialist in S...
baharayali
 

Kürzlich hochgeladen (20)

St John's Church Parish Diary for May 2024
St John's Church Parish Diary for May 2024St John's Church Parish Diary for May 2024
St John's Church Parish Diary for May 2024
 
Famous Kala Jadu, Black magic expert in UK and Kala ilam expert in Saudi Arab...
Famous Kala Jadu, Black magic expert in UK and Kala ilam expert in Saudi Arab...Famous Kala Jadu, Black magic expert in UK and Kala ilam expert in Saudi Arab...
Famous Kala Jadu, Black magic expert in UK and Kala ilam expert in Saudi Arab...
 
Verified Amil baba in Pakistan Amil baba in Islamabad Famous Amil baba in Ger...
Verified Amil baba in Pakistan Amil baba in Islamabad Famous Amil baba in Ger...Verified Amil baba in Pakistan Amil baba in Islamabad Famous Amil baba in Ger...
Verified Amil baba in Pakistan Amil baba in Islamabad Famous Amil baba in Ger...
 
Genesis 1:2 - Meditate the Scripture Daily bit by bit
Genesis 1:2 - Meditate the Scripture Daily bit by bitGenesis 1:2 - Meditate the Scripture Daily bit by bit
Genesis 1:2 - Meditate the Scripture Daily bit by bit
 
Genesis 1:7 || Meditate the Scripture daily verse by verse
Genesis 1:7  ||  Meditate the Scripture daily verse by verseGenesis 1:7  ||  Meditate the Scripture daily verse by verse
Genesis 1:7 || Meditate the Scripture daily verse by verse
 
Famous Kala Jadu, Black magic specialist in Rawalpindi and Bangali Amil baba ...
Famous Kala Jadu, Black magic specialist in Rawalpindi and Bangali Amil baba ...Famous Kala Jadu, Black magic specialist in Rawalpindi and Bangali Amil baba ...
Famous Kala Jadu, Black magic specialist in Rawalpindi and Bangali Amil baba ...
 
Emails, Facebook, WhatsApp and the Dhamma (English and Chinese).pdf
Emails, Facebook, WhatsApp and the Dhamma  (English and Chinese).pdfEmails, Facebook, WhatsApp and the Dhamma  (English and Chinese).pdf
Emails, Facebook, WhatsApp and the Dhamma (English and Chinese).pdf
 
Popular Kala Jadu, Black magic expert in Karachi and Kala jadu expert in Laho...
Popular Kala Jadu, Black magic expert in Karachi and Kala jadu expert in Laho...Popular Kala Jadu, Black magic expert in Karachi and Kala jadu expert in Laho...
Popular Kala Jadu, Black magic expert in Karachi and Kala jadu expert in Laho...
 
Popular Kala Jadu, Black magic specialist in Sialkot and Kala ilam specialist...
Popular Kala Jadu, Black magic specialist in Sialkot and Kala ilam specialist...Popular Kala Jadu, Black magic specialist in Sialkot and Kala ilam specialist...
Popular Kala Jadu, Black magic specialist in Sialkot and Kala ilam specialist...
 
St. John's Church Parish Magazine - May 2024
St. John's Church Parish Magazine - May 2024St. John's Church Parish Magazine - May 2024
St. John's Church Parish Magazine - May 2024
 
From The Heart v8.pdf xxxxxxxxxxxxxxxxxxx
From The Heart v8.pdf xxxxxxxxxxxxxxxxxxxFrom The Heart v8.pdf xxxxxxxxxxxxxxxxxxx
From The Heart v8.pdf xxxxxxxxxxxxxxxxxxx
 
St. Louise de Marillac and Galley Prisoners
St. Louise de Marillac and Galley PrisonersSt. Louise de Marillac and Galley Prisoners
St. Louise de Marillac and Galley Prisoners
 
NoHo First Good News online newsletter May 2024
NoHo First Good News online newsletter May 2024NoHo First Good News online newsletter May 2024
NoHo First Good News online newsletter May 2024
 
Codex Singularity: Search for the Prisca Sapientia
Codex Singularity: Search for the Prisca SapientiaCodex Singularity: Search for the Prisca Sapientia
Codex Singularity: Search for the Prisca Sapientia
 
Christian Charism Ministry - Manifestation of spiritual gifts within the chur...
Christian Charism Ministry - Manifestation of spiritual gifts within the chur...Christian Charism Ministry - Manifestation of spiritual gifts within the chur...
Christian Charism Ministry - Manifestation of spiritual gifts within the chur...
 
Amil baba in Lahore /Amil baba in Karachi /Amil baba in Pakistan
Amil baba in Lahore /Amil baba in Karachi /Amil baba in PakistanAmil baba in Lahore /Amil baba in Karachi /Amil baba in Pakistan
Amil baba in Lahore /Amil baba in Karachi /Amil baba in Pakistan
 
Famous Kala Jadu, Black magic specialist in Lahore and Kala ilam expert in ka...
Famous Kala Jadu, Black magic specialist in Lahore and Kala ilam expert in ka...Famous Kala Jadu, Black magic specialist in Lahore and Kala ilam expert in ka...
Famous Kala Jadu, Black magic specialist in Lahore and Kala ilam expert in ka...
 
St. Louise de Marillac and Abandoned Children
St. Louise de Marillac and Abandoned ChildrenSt. Louise de Marillac and Abandoned Children
St. Louise de Marillac and Abandoned Children
 
Authentic Black magic, Kala ilam expert in UAE and Kala ilam specialist in S...
Authentic Black magic, Kala ilam expert in UAE  and Kala ilam specialist in S...Authentic Black magic, Kala ilam expert in UAE  and Kala ilam specialist in S...
Authentic Black magic, Kala ilam expert in UAE and Kala ilam specialist in S...
 
"The Magnificent Surah Rahman: PDF Version"
"The Magnificent Surah Rahman: PDF Version""The Magnificent Surah Rahman: PDF Version"
"The Magnificent Surah Rahman: PDF Version"
 

Practical OData

  • 1. Vagif Abilov Miles AS vagif.abilov@gmail.com @ooobject github: object http://bloggingabout.net/blogs/vagif/
  • 2.  OData and REST  WCF Data Services  OData feed in 5 minutes: EF + MS SQL  The power of ObjectContext  Using reflection provider  Using custom providers and NoSQL  Extending OData services  Performance and diagnostics  A song about OData
  • 3. Are you familiar with OData? Have you used OData in your projects? Do you have components on your machine that use OData communication?
  • 4.  The Open Data Protocol (OData) is a Web protocol for querying and updating data  Consumers query a datasource over HTTP and get results back in formats like AtomPub, JSON or plain XML  OData follows many of the principles of REST
  • 5.
  • 6.
  • 7.
  • 8. Querying NuGet feed with LINQPad Importing data from OData feed into Microsoft Excel using PowerPivot
  • 9.  Command content specified in URIs  Use of HTTP verbs (GET, POST, PUT, DELETE)  Use of HTTP status codes  Response sent as XML (AtomPub) or JSON  Related content specified using link elements
  • 11. Method Safe Idempotent GET Yes Yes POST No No PUT No Yes DELETE No Yes
  • 13. http://localhost.:50555/InMemory.svc/ Customers <entry term="Northwind.InMemory.Customers" /> <content type="application/xml"> <m:properties> <d:CompanyName>My Company</d:CompanyName> <d:CustomerID>TEMP</d:CustomerID> </m:properties> </content> </entry>
  • 14. http://localhost.:50555/InMemory.svc/ Customers(„TEMP') <entry term="Northwind.InMemory.Customers" /> <content type="application/xml"> <m:properties> <d:CompanyName>My New Company</d:CompanyName> <d:CustomerID>TEMP</d:CustomerID> </m:properties> </content> </entry>
  • 16. Request: a company with non-existing CompanyName Response: an empty collection Request: a company with non-existing CompanyID Response: 404 Not Found
  • 17. var ctx = new NorthwindContext("http://localhost.:50555/InMemory.svc"); ctx.IgnoreResourceNotFoundException = true; var customers = from c in ctx.Customers where c.CustomerID == "XYZ" select c;
  • 18.  Formerly ADO.NET Data Services  Codename “Astoria”  OData provider library for .NET  Not to be confused with WCF RIA Services designed specifically for end-to-end Silverlight and ASP.NET applications
  • 19.  Using Entity Framework provider • EF model first+ MS SQL – trivial • EF code first, different DB vendors – easy  Using reflection provider • Any context exposing a set of IQueryable properties – easy • Implementing IUpdatable for updatable OData feeds – easy  Using custom provider • OData provider toolkit usually helps – still complex
  • 20. public class EntityFrameworkModelFirstMsSql : DataService<NorthwindMsSqlContext> { public static void InitializeService(DataServiceConfiguration config) { config.SetEntitySetAccessRule("*", EntitySetRights.All); config.SetServiceOperationAccessRule("*", ServiceOperationRights.All); config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2; } protected override NorthwindMsSqlContext CreateDataSource() { return new NorthwindMsSqlContext(/* connection string */); } }
  • 21.  As simple as with MS SQL assuming EF provider for the respective vendor is available  Proven choice: Devart dotConnect product family: • Oracle • MySQL • PostgreSQL • SQLite
  • 22.  Not supported by tools  EDMX is just an XML file with 3 main sections: • Conceptual model (CSDL) • Storage model (SSDL) • Mapping (MSL)  You can author your own EF model: • Support for n database vendors • 2n + 1 XML sections (1 CSDL + n SSDL + n MSL)
  • 23.  DbContext class, wraps ObjectContext  Model is generated from entities  Database can be generated from the model  Convention over configuration reduces configuration code to bare minimum  No more trick to share conceptual model between databases from different vendors
  • 24. public class NorthwindContextBase : DbContext { public ObjectContext ObjectContext { get { return (this as IObjectContextAdapter).ObjectContext; } } } public class EntityFrameworkCodeFirstMsSql : DataService<ObjectContext> { protected override ObjectContext CreateDataSource() { var ctx = new NorthwindContext("NorthwindContext.EF.CF.MsSql"); return ctx.ObjectContext; } }
  • 25.  Suitable for most of scenarios with static resource set information (schema known at compile time)  Resource sets exposed as IQueryable<T> properties of the context class  DataServiceKey attribute specifies entity key  Optional support for IUpdatable
  • 26. OData feed exposing in-memory data collection OData feed using NHibernate to access MS SQL database
  • 27.  Entity Framework provider is the quickest way to add OData feed on the top of a popular SQL database  Reflection provider covers most of other scenarios when the data schema is known up-front  Custom provider is needed when the schema is discovered at runtime or data don‟t have fixed types
  • 28.  If the content of NoSQL database is known at compile time, reflection provider can be used  If the content of NoSQL database is divided into collections of fixed types, the resource sets can be built at runtime  If the content is untyped, OData feed can still be built using open types
  • 29. Creating OData feed for MongoDB using WCF Data Services and OData Provider Toolkit
  • 30.  OData data model supports open types for Entries. An entry of an open type may have extra properties (dynamic properties) in addition to those statically declared in metadata  WCF Data Services framework takes care of transforming the incoming requests into an expression tree. Custom code is responsible for evaluation expression tree against the data store
  • 31.  Custom service operations can only use HTTP GET and POST  Generated client context code does not include custom service operations – it has to be added manually  Default webHttpBinding settings may not be sufficient for large payload (send/receiveTimeout, maxBufferSize and maxStringContentLength often need to be increased)
  • 32. [WebInvoke(Method = "POST")] public void DeleteProductsByNamePattern(string namePattern) { this.CurrentDataSource.ExecuteStoreCommand( string.Format("DELETE FROM Products WHERE ProductName LIKE '{0}%'", namePattern)); }
  • 33. public void DeleteProductsByNamePattern(string namePattern) { HttpWebRequest request = (HttpWebRequest)WebRequest.Create( string.Format("{0}/DeleteProductsByNamePattern?namePattern={1}", this.BaseUri, namePattern)); request.Method = "POST"; request.Accept = "application/atom+xml,application/xml"; request.ContentType = "application/atom+xml"; request.ContentLength = 0; HttpWebResponse response = (HttpWebResponse)request.GetResponse(); }
  • 34.  OData design goal is to provide data publishing protocol for services, not for low-level components  Don‟t use OData to implement cascaded updates and deletes of large number of dependent entities  Understand the difference between client- side and server-side operations
  • 35.  LINQPad (LINQ to OData)  Fiddler  RedGate .NET Reflector Pro (to step-in to WCF Data Services code)  Oren Eini‟s profilers (EF Profiler, NHibernate Profiler)  Elmah logging framework (install it using NuGet, it will update your web.config)
  • 36.  Don‟t reinvent the wheel, don‟t come with your own standards  Consider OData to expose data sources on the Web  Don‟t treat OData as a SQL database publisher  Writing OData feeds is easy
  • 37.  Code examples for this presentation: https://github.com/object/ NorthwindOData  Open Data Protocol: http://www.odata.org/ http://www.odata.org/mailing-list  WCF Data Services forum: http://social.msdn.microsoft.com/Forums/e n/adodotnetdataservices/
  • 38.  WCF Data Services Toolkit: http://wcfdstoolkit.codeplex.com/  Microsoft WCF Data Services March 2011 CTP 2 for .NET Framework 4 and Silverlight 4: http://www.microsoft.com/downloads/en/de tails.aspx?FamilyID=60fb0117-8cea-4359- b392-6b04cdc821be
  • 40. OData! Please relieve me AtomPub is what I‟m gonna need Believe me when I tell you: AtomPub is what I‟m gonna need
  • 41. OData! Please relieve me JSON‟s what I want in JavaScript Believe me when I tell you: JSON‟s what I want in JavaScript
  • 42. When you told me: “Internal error 500” Oh well you know, I nearly broke down and cried When you told me: “Internal error 501” Oh well you know, I nearly broke down and died
  • 43. OData! Please relieve me I want to live a RESTful life Believe me when I tell you: I want to live a RESTful life
  • 44.  Vagif Abilov  Miles AS  vagif.abilov@gmail.com  @ooobject  github: object  http://bloggingabout.net/blogs/vagif/