Diese Präsentation wurde erfolgreich gemeldet.
Die SlideShare-Präsentation wird heruntergeladen. ×

Introduction to OData

Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Nächste SlideShare
Odata
Odata
Wird geladen in …3
×

Hier ansehen

1 von 29 Anzeige

Introduction to OData

Herunterladen, um offline zu lesen

This presentation is at the beginners level and mainly focusses on how to create and consume OData service in ASP.NET. OData (Open Data Protocol) is a standardized protocol for creating and consuming data APIs through regular HTTP requests and REST.

This presentation is at the beginners level and mainly focusses on how to create and consume OData service in ASP.NET. OData (Open Data Protocol) is a standardized protocol for creating and consuming data APIs through regular HTTP requests and REST.

Anzeige
Anzeige

Weitere Verwandte Inhalte

Diashows für Sie (20)

Ähnlich wie Introduction to OData (20)

Anzeige

Weitere von Mindfire Solutions (20)

Aktuellste (20)

Anzeige

Introduction to OData

  1. 1. 1 Presenter: Dukhabandhu Sahoo, Mindfire Solutions Date: 18-May-2015 Introduction to OData
  2. 2. About Me Presenter: Dukhabandhu Sahoo, Mindfire Solutions Connect With Me: Twitter: https://twitter.com/dbsahoo99 FaceBook: http://www.facebook.com/dukhabandhusahoo LinkedIn: http://www.linkedin.com/in/dukhabandhusahoo Google+: https://plus.google.com/+DukhabandhuSahoo Blog: http://dukhabandhu.wordpress.com/ Contact Me: Email: dukhabandhus@mindfiresolutions.com Skype: mfsi_dukhabandhus MCTS Certifications: 1. Developing ASP.NET MVC Web Applications(70-486) 2. Web Applications Development with Microsoft .NET Framework 4(70-515) 3. Programming in HTML5 with JavaScript and CSS3(70-480)
  3. 3. Agenda Presenter: Dukhabandhu Sahoo, Mindfire Solutions - What is OData? - How it is different from SOAP, POX? - OData Server Platforms - OData implementation using WCF Data Service - OData implementation using ASP.NET Web API - OData query operators and methods
  4. 4. - It stands for Open Data access protocol. - An open protocol to allow the creation and consumption of queryable and interoperable RESTful APIs in a simple and standard way. (Odata.org) - It is a RESTful architecture and supports most of the HTTP verbs(GET, POST, PUT, DELETE, PATCH, MERGE) - It supports three types of data formatting: ATOMPub(XML), JSON, and JSON light. What is OData? Presenter: Dukhabandhu Sahoo, Mindfire Solutions
  5. 5. - It stands for Simple Object Access Protocol. - It is mainly operation(Verb) focused and supports HTTP POST only. - It is based on XML and contains lots of meta-data. So it is little slower. Example: <s:Envelope xmlns:s=""> <s:Headers> </s:Headers> <s:Body> </s:Body> </s:Envelope> SOAP Presenter: Dukhabandhu Sahoo, Mindfire Solutions
  6. 6. - It stands for Plain Old XML. - Since it is XML based so it is platform independent. - POX is more interoperable than SOAP because clients no longer need a SOAP client to consume the web service. They can access it by using a standard Web Client and an XML parser. - But again it supports only XML format which forces the clients to use XML parser. You cannot use JSON which is lighter than XML. POX Presenter: Dukhabandhu Sahoo, Mindfire Solutions
  7. 7. - It stands for REpresentational State Transfer. - Representation of resources(e.g List of Products, Remote Desktop, etc.) - REST is an architectural style not an protocol unlike SOAP and HTTP. - It fully supports HTTP and it is less coupled to the server. REST Presenter: Dukhabandhu Sahoo, Mindfire Solutions
  8. 8. OData features Presenter: Dukhabandhu Sahoo, Mindfire Solutions
  9. 9. - WCF Data Services - Share Point, MS SQL Server Reporting Services, Windows Azure, ASP.NET Web API - Node.js, PHP, Java, IBM WebSphere/DB2/Informix - OData producers are services that expose their data using the OData protocol. - http://www.odata.org/ecosystem/ OData Server Platforms Presenter: Dukhabandhu Sahoo, Mindfire Solutions
  10. 10. - No WCF knowledge needed. - Complete implementation of the latest OData specification. - Complicated if you want to use non-LINQ data provider. - Simple and Fast OData Using WCF Data Service Presenter: Dukhabandhu Sahoo, Mindfire Solutions
  11. 11. - Add WCF Data Service File and install Nuget package Microsoft.Data.Services.Client. - If Entity Framework 6 is used for data provide then we need to install Microsoft.OData.EntityFrameworkProvider(-Pre) package. - Instead of DataService<T> we have to use EntityFrameworkDataService<T>( http://tinyurl.com/wcfdataservice-ef6) - We can use custom data provider which returns IQueryable<T> type WCF Data Service - Demo Presenter: Dukhabandhu Sahoo, Mindfire Solutions
  12. 12. - Create new service operation. - Add the appropriate service operation verb attribute(e.g [WebGet]) - Allow access by registering the method in the service constructor. - For custom data providers use [DataServiceKey("Name")] attribute for providing the key column of the entity. WCF Data Service(Contd...) Presenter: Dukhabandhu Sahoo, Mindfire Solutions
  13. 13. - There are two types of interceptor: QueryInterceptor and ChangeInterceptor - The QueryInterceptor is used for GET request and it takes the entity set name as parameter and its return type is Expression<Func<TEntitySet, bool>> - The ChangeInterceptor is used for non-GET requests and has void as return type. - ChangeInterceptor method implementation takes first parameter as entity type and second parameter as UpdateOperations type. Interceptors in WCF Data Service Presenter: Dukhabandhu Sahoo, Mindfire Solutions
  14. 14. WCF Data Service Diagram Presenter: Dukhabandhu Sahoo, Mindfire Solutions
  15. 15. - Check that the entity has full permission enabled (EntitySetRights.All). - Create: POST( http://localhost:2194/DataServiceTest.svc/Products) - Read: GET(http://localhost:2194/DataServiceTest.svc/Products(78)) - Update: PUT(http://localhost:2194/DataServiceTest.svc/Products(78)) - Delete: DELETE(http://localhost:2194/DataServiceTest.svc/Products(78)) CRUD in WCF Data Service Presenter: Dukhabandhu Sahoo, Mindfire Solutions
  16. 16. - The controller class inherits from ODataController class. - To expose data in GET request, create method of return type IQueryable<TEntity>. - Add [EnableQuery]/[Queryable] attribute at the top of the method. - All the entities exposed via OData using Entity Framework must have a key column. OData using Web API Presenter: Dukhabandhu Sahoo, Mindfire Solutions
  17. 17. - To get the metadata go to URL http://localhost:2674/odata/$metadata - http://localhost:2674/odata/Products? $top=3&$skip=3&$select=ProductName - http://localhost:2674/odata/Products?$filter=ProductID gt 5 and ProductID lt 8 - http: //services.odata.org/Northwind/Northwind.svc/ Customers?$filter=startswith(CompanyName, 'Alfr') - The OData URL is case-sensitive. Querying in Web API Presenter: Dukhabandhu Sahoo, Mindfire Solutions
  18. 18. - - Querying in OData Presenter: Dukhabandhu Sahoo, Mindfire Solutions
  19. 19. http://services.odata.org/OData/OData.svc/ /Products?$filter=ID eq 1 /Products?$orderby=Name desc /Products?$top=2 /Products?$skip=10 /Products?$select=Rating,ReleaseDate /Products?$inlinecount=allpages (<m:count>11</m:count>) /Categories?$expand=Products&$select=Name,Products/Name&$top=1 /Products(1)/Name /Products(1)/Name/$value OData Query Examples Presenter: Dukhabandhu Sahoo, Mindfire Solutions
  20. 20. OData Logical Operators Presenter: Dukhabandhu Sahoo, Mindfire Solutions /Products?$filter=ID le 105 and ID gt 100 /Products?$filter=ID ge 10 /Products?$filter=Name ne 'Chai'
  21. 21. OData Arithmetic Operators Presenter: Dukhabandhu Sahoo, Mindfire Solutions /Products?$filter=ID add 5 gt 10 /Products?$filter=ID sub 5 gt 10 /Products?$filter=ID mul 2 gt 100 /Products?$filter=ID div 5 gt 10 /Products?$filter=ID mod 2 eq 0
  22. 22. String Functions in OData Presenter: Dukhabandhu Sahoo, Mindfire Solutions /Products?$filter=substring(Name, 1) eq 'hai' /Products?$filter=substring(Name, 1, 2) eq 'ha' /Products?$filter=substringof('lk', Name) eq true /Products?$filter=indexof(Name, 'hai') eq 1 /Products?$filter=startswith(Name, 'a') /Products?$filter=replace(Name, '-', '') eq 'Test' /Products?$filter=tolower(Name) eq 'chai' /Products?$filter=trim(Name) eq 'milk'
  23. 23. Date Functions in OData Presenter: Dukhabandhu Sahoo, Mindfire Solutions /Employees?$filter=year(BirthDate) eq 1989 /Employees?$filter=minute(BirthDate) eq 20 /Employees?$filter=second(BirthDate) eq 40
  24. 24. Math Functions in OData Presenter: Dukhabandhu Sahoo, Mindfire Solutions /Orders?$filter=round(Freight) eq 32 /Orders?$filter=floor(Freight) eq 30 /Orders?$filter=ceiling(Freight) eq 300 Currently no aggregate functions are supported in OData. You can add service operation/custom method to expose the aggregate functions.
  25. 25. OData Response Formats Presenter: Dukhabandhu Sahoo, Mindfire Solutions ATOMPub User-Agent: Fiddler Accept: application/atom+xml GET: http://services.odata.org/northwind/northwind.svc/Products JSON Verbose User-Agent: Fiddler Accept: application/json;odata=verbose JSON Light User-Agent: Fiddler Accept: application/json The response size order is: ATOMPub > JSON Verbose > JSON Light
  26. 26. Recap Presenter: Dukhabandhu Sahoo, Mindfire Solutions - How OData is different from SOAP, POX? - OData server platforms and consumers. - OData implementation using WCF Data Service - QueryInterceptor and ChangeInterceptor - OData implementation using Web API - Querying in OData(using $filter, $select, $top, etc.) - Logical and arithmetic operators in OData - String and date functions in OData
  27. 27. References Presenter: Dukhabandhu Sahoo, Mindfire Solutions http://www.odata.org https://msdn.microsoft.com/en-us/library/dd541437.aspx http://en.wikipedia.org/wiki/Open_Data_Protocol http://www.asp.net/web-api/overview/odata-support- in-aspnet-web-api
  28. 28. Questions? Presenter: Dukhabandhu Sahoo, Mindfire Solutions
  29. 29. Thank You Presenter: Dukhabandhu Sahoo, Mindfire Solutions

×