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

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.

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 

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:

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.

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:

Image _thumb 11

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:

Image _thumb 12

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

Image _thumb2

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:

Image 9_thumb

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:

Image _thumb 13

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!

Image _thumb 14

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 _thumb6

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 _thumb7

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

1
2
3
4
5
6
7
8
9
10
11
12
<?xmlversion=”1.0″encoding=”utf-8″?>
<Elementsxmlns=”http://schemas.microsoft.com/sharepoint/”>
<ListInstanceUrl=”Lists/Video”Description=”Video”OnQuickLaunch=”TRUE”Title=”Video”>
<DataSource>
<PropertyName=”LobSystemInstance”Value=”Telerik OData”/>
<PropertyName=”EntityNamespace”Value=”TelerikTvDataServiceDataServiceModels”/>
<PropertyName=”Entity”Value=”Video”/>
<PropertyName=”SpecificFinder”Value=”ReadSpecificVideo”/>
<PropertyName=”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:

External Content Type

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

External Content Type

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:

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

External Content Type

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.

This blog was first published by Tobias Zimmergren. Check out our resource centre for more SharePoint content from Tobias and other SharePoint specialists!

Share this on...

Rate this Post:

Share: