1. O, There’s My Data
The Open Data Protocol (OData)
Steve Hughes
Principal Consultant, Magenic
7/17/2012
Minnesota SQL Server User Group Meeting
2. I called you all here …
» Mark Souza
» Why use OData?
» Is it really necessary for Data Pros?
3. Introducing the Open Data Protocol
» Commonly known as OData
» Built on established protocols
» REST
» Atom
» HTTP
» Open specification from Microsoft
» Designed to expose data from a variety of sources
4. OData Feeds
» Data structure support
» Tables
» Foreign keys
» Stored procedures
» Data type support
» Originally designed to support SQL 2008 and Entity Framework
» Designed to be flexible
» For example, Oracle EF implementation can be supported
5. Entity Data Model
» This is the structure of the feed
» Entity Type
» Individual entity in the feed, similar to a row
» Entity Key
» One or more entity properties making each entity type unique in the feed
» Entity Set
» Collection of entities, essentially a table
» Service Operation
» Function or stored procedures that can be used in the feed
7. Windows Communication Foundation
» “WCF is a unified programming model for building service-oriented
applications.” – MSDN (http://msdn.microsoft.com/en-
us/library/dd936243.aspx)
» WCF supports multiple network protocols including HTTP and TCP
» WCF supports multiple message formats such as SOAP and REST
» We will use a WCF project to expose an OData feed based on our entity
model
8. Building a WCF Service
Using Visual Studio to create the WCF Data Service
11. Painful OData Support a.k.a. SSIS
» SSIS does not natively support OData feeds
» My goal – use OData as an SSIS Source
» Technology tried along the way
» LINQ
» Able to connect to the feed but not the right tool for SSIS
» ATOM & XML
» Works – creates files on the server, not the best option, but it works
» DataServiceQuery
» Works – allows us to create SSIS Source task which returns rows
12. OData Feed in SSIS
Showing how to retrieve data from OData feeds in SSIS
13. References
» Connecting to Windows Azure SQL Database Through WCF:
http://msdn.microsoft.com/en-us/library/windowsazure/ee621789.aspx
» Loading Data from an ATOM Data Feed into SQL Server:
http://channel9.msdn.com/Learn/Courses/SQL2008R2TrainingKit/SQL10R2UPD01/S
QL10R2UPD01_HOL_03/Exercise-1-Loading-Data-from-an-ATOM-Data-Feed-into-
SQL-Server
» SSIS – Using a Script Component as a Source
http://www.ssistalk.com/2007/04/04/ssis-using-a-script-component-as-a-source/
» DataServiceContext Class: http://msdn.microsoft.com/en-
us/library/system.data.services.client.dataservicecontext.aspx
» Chris Woodruff – 31 Days of OData Blog Series:
http://chriswoodruff.com/2011/11/19/announcing-the-31-days-of-odata-blog-
series/
14. Wrap Up
» Creating an OData feed requires .NET coding
» Consuming an OData feed – Native vs Custom
»Q&A
15. Steve Hughes
» Principal Consultant with Magenic
» Over 15 years with SQL Server
» Chair of Minnesota SQL Server User Group (PASSMN)
» PASS Regional Mentor for US-NorthEast Region
» Contact Info
» Blog: http://www.dataonwheels.com
» Twitter: @DataOnWheels
» Email: steveh@magenic.com
Editor's Notes
New ProjectUse WCF Service Application TemplateNeed to Run As Admin to support IIS workRemove .cs file and App_Data, not needed for this solutionAdd New Item – Data – ADO.NET Entity Data ModelUse Wizard and Generate from DatabaseChoose data connection – AdventureWorks 2008 versionChoose your database objectsChoosing Department and EmployeeClick Finish to generate modelView model browser – note entity sets are pluralized entity types
Add New Item – Web – WCF Data Service(remove other service)Open .svc.cs fileAdd DataService Name in class definitionAdd config.SetEntitySetAccessRule(“MyEntitySet”,EntitySetRights.AllRead); for each table to be exposed as an entity setDebug - .svc file to see Atom definition
In PowerPivot windowChoose Connect to a Data FeedGive it a nameUse the URL from the feed - .svcChoose tables which are actually entity setsClick finishNOTE: for my demo to work I needed to change the connection string in the package to use an SQL user. Otherwise it will pass windows credentials, I am not on a domain so that is likely my issue.
Walk through both packagesStart with UsingATOMCreate ATOM FileProcess ATOM FileLoad DataThen UsingRSSGet ODataSource Script Component walk through