SharePoint 2013: Business Connectivity Services – Consuming OData in BCS using an App External Content Type

Author: Tobias Zimmergren
http://www.zimmergren.net | http://www.tozit.com | @zimmergren

Introduction

As most if not all of you already know, SharePoint 2013 and Office 2013 has been released to preview/beta and is available for download from Microsoft’s download centers. In this article I will briefly introduce some exciting changes that has been made to the SharePoint 2013 Business Connectivity Services framework. I’ve written a bunch of articles on BCS for SharePoint 2010, and now it’s time to continue that track and introduce the new features available in SharePoint 2013.

[blockquote]

Please note that this article is written for SharePoint 2013 Preview, and for the final version of SharePoint some details may have changed

  1. SharePoint 2013: Business Connectivity Services – Introduction
  2. SharePoint 2013: Business Connectivity Services – Consuming OData in BCS Using an App External Content Type
  3. SharePoint 2013: Business Connectivity Services – Talking to your external lists using REST
  4. SharePoint 2013: Business Connectivity Services – Client Object Model
  5. SharePoint 2013: Business Connectivity Services – Events and Alerts

[/blockquote]

SharePoint 2013 – BCS with OData

In this specific article we’ll be looking on how you can consume data from an Open Data protocol (OData) data source. Tag along for the ride!

First of all, tell me what OData is…!?

Right, so OData is a  Web protocol for performing CRUD (Create Read Update and Delete) operations and utilizes technologies like HTTP, ATOM and JSON.

As quoted from the OData Web Site:

[blockquote]

The Open Data Protocol (OData) is a Web protocol for querying and updating data that provides a way to unlock your data and free it from silos that exist in applications today.
OData does this by applying and building upon Web technologies such as HTTP, Atom Publishing Protocol (AtomPub) and JSON to provide access to information from a variety of applications, services, and stores.

[/blockquote]

We can have lengthy discussions about how awesome (or unawesome) OData is but in this article we’ll be focusing on consuming OData data sources in SharePoint 2013 through Business Connectivity Services, one of my favorite parts of SharePoint.

Launch Visual Studio and get started!

So, as you probably could tell by the title of this post – you should now open Visual Studio 2012 :-)

Create the project

Choose the project type App for SharePoint 2013:

SharePoint 2013 bcs odata app

The Wizard that launches will give you a few choices which we’ll discuss in another article. In this article I’ve selected the “SharePoint Hosted” alternative, as you can see below:

SharePoint 2013 bcs odata app

This should get you setup with the initial project structure, and you should now have a project that looks something like this:

SharePoint 2013 bcs odata app project

Add an external content type

Now that we’ve created our initial project, we should add a new external content type. If you right-click your project and choose Add, you can see that there’s a new menu item called “Content Types for an External Data Source…“. Click it:

SharePoint 2013 bcs content type

In the following wizard, you can enter the service URL for the OData provider you’d like to consume. In my example I’ve used the public tv.telerik.com/services/odata.svc OData service:

Telerik OData in SharePoint 2013

In the next step in the wizard, you get to select for which data entities you want to generate external content types. Choose the entities you’d like to work with and continue by pressing Finish:
Please note that you should leave the “Create list instances for the selected data entries (except Service Operations).” checked so the tools can create your external list automatically!

SharePoint 2013 BCS Entity

After we’ve completed this step, we can see a few additions in our project that Visual Studio 2012 has been so kind to help us out with.

A Telerik Video external content type with it’s associated ListInstances (one per entity, in my case only one for Video) that it was also kind enough to create for us since I had the checkbox in the previous dialog ticked:

image

Looking in your Feature explorer, you can see that the default Feature now contains your artifacts along with the newly created List Instance and External Content Type:

image

In the newly created List Instances, the following XML has been generated for us:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <ListInstance Url="Lists/Video" Description="Video" OnQuickLaunch="TRUE" Title="Video">
    <DataSource>
      <Property Name="LobSystemInstance" Value="Telerik OData" />
      <Property Name="EntityNamespace" Value="TelerikTvDataServiceDataServiceModels" />
      <Property Name="Entity" Value="Video" />
      <Property Name="SpecificFinder" Value="ReadSpecificVideo" />
      <Property Name="MetadataCatalogFileName" Value="BDCMetadata.bdcm" />
    </DataSource>
  </ListInstance>
</Elements>

As you can see, the ListInstance DataSource node contains information about connecting to our newly created BCS entity. Perfect.

Just to make sure that we can deploy our solution, hit F5 and make sure that VS2012 deploys your project properly

Validate that your application works

Navigate to your site and validate that your new App is properly deployed and showing:

SharePoint 2013 app

Click the app and make sure you can see the result of your very basic and “hello world”-ish app:

image

Display your new external list!

Do you remember in one of the previous steps that I mentioned that you should leave the checkbox ticked in a dialog, saying “Create list instances for the selected data entries (except Service Operations).”? Well the reason for that is that we want Visual Studio 2012 tools to create this list for us so we don’t have to do that ourselves.

With the newly deployed BCS external content type app, with it’s created list, you can access the content of the list on the following URL (you’ll need to check your Elements.xml for your ListInstance element in order to find out your url:

http://yourappurl/ZimmergrenSP2013BCSOData/Lists/Video

Navigate to this URL and you’ll see this view:

SharePoint 2013 BCS OData Telerik Tv

So that’s pretty cool and easy right? Straight from the XML-formatted OData source we’ve pulled some info into our App in SharePoint.

Summary

As you can see, working with SharePoint 2013 and the OData model with BCS is pretty straight forward. In this example I created an App for SharePoint utilizing the BCS framework to connect to an OData data source. I’m pretty impressed with the options this opens up for many of our existing SharePoint 2010 projects that sometime in the future will be upgraded to SharePoint 2013.

In the next few posts we’ll dive more into the news around BCS for SharePoint 2013.

Enjoy.

Follow me

Tobias Zimmergren

Founder / Consultant / Advisor at TOZIT AB
Tobias Zimmergren delivers high-quality articles about business and technology around the Microsoft scene.

Tobias focuses on advisory and consultancy for the Office 365 and SharePoint offerings from Microsoft.
Follow me