Ready to get started?

Download a free trial of the HubDB Data Provider to get started:

 Download Now

Learn more:

HubDB Icon HubDB ADO.NET Provider

Rapidly create and deploy powerful .NET applications that integrate with HubDB.

Provide OData Services of HubDB Data from a WCF Application



In this article, we will demonstrate the process of generating an OData feed for HubDB data by developing a WCF Service Application.

The CData ADO.NET Provider for HubDB enables you to rapidly develop service-oriented applications using the Windows Communication Foundation (WCF) framework, providing HubDB data data to OData consumers. This article guides you through creating an entity data model for connectivity and a WCF Data Service to expose OData services. You can then consume the feed with various OData clients, such as Power Pivot or applications using the CData ADO.NET Provider for OData.

Create the OData Service

Follow the steps below to create a WCF service application that will provide connectivity to HubDB data via OData.

  1. Open Visual Studio and create a new project. Select the WCF Service Application template.
  2. Delete the autogenerated IService.cs and Service1.svc.
  3. Install Entity Framework 6:

    Use the Package Manager Console in Visual Studio to install the latest version of Entity Framework. Run the following command to download and install Entity Framework automatically: Install-Package EntityFramework

  4. Register the Entity Framework provider:
    1. Add the following provider entry in the "providers" section of your App.config or Web.config file. This section should already exist if the Entity Framework installation was successful. <configuration> ... <entityFramework> <providers> ... <provider invariantName="System.Data.CData.HubDB" type="System.Data.CData.HubDB.HubDBProviderServices, System.Data.CData.HubDB.Entities.EF6" /> </providers> </entityFramework> </configuration>
    2. Add a reference to System.Data.CData.HubDB.Entities.dll, located in lib/4.0 in the installation directory.
    3. Build the project to complete the setup for using EF6.
  5. Click Project -> Add New Item -> ADO.NET Entity Data Model.
  6. In the Entity Data Model wizard that is displayed, select the 'EF Designer from Database' option.
  7. In the resulting Choose Your Connection dialog, click New Connection.
  8. In the Connection properties dialog, select the CData HubDB Data Source and enter the necessary credentials.

    A typical connection string is below:

    AuthScheme=OAuth;OAuthClientID=MyOAuthClientID;OAuthClientSecret=MyOAuthClientSecret;CallbackURL=http://localhost:33333;InitiateOAuth=GETANDREFRESH

    There are two authentication methods available for connecting to HubDB data source: OAuth Authentication with a public HubSpot application and authentication with a Private application token.

    Using a Custom OAuth App

    AuthScheme must be set to "OAuth" in all OAuth flows. Be sure to review the Help documentation for the required connection properties for you specific authentication needs (desktop applications, web applications, and headless machines).

    Follow the steps below to register an application and obtain the OAuth client credentials:

    1. Log into your HubSpot app developer account.
      • Note that it must be an app developer account. Standard HubSpot accounts cannot create public apps.
    2. On the developer account home page, click the Apps tab.
    3. Click Create app.
    4. On the App info tab, enter and optionally modify values that are displayed to users when they connect. These values include the public application name, application logo, and a description of the application.
    5. On the Auth tab, supply a callback URL in the "Redirect URLs" box.
      • If you're creating a desktop application, set this to a locally accessible URL like http://localhost:33333.
      • If you are creating a Web application, set this to a trusted URL where you want users to be redirected to when they authorize your application.
    6. Click Create App. HubSpot then generates the application, along with its associated credentials.
    7. On the Auth tab, note the Client ID and Client secret. You will use these later to configure the driver.
    8. Under Scopes, select any scopes you need for your application's intended functionality.

      A minimum of the following scopes is required to access tables:

      • hubdb
      • oauth
      • crm.objects.owners.read
    9. Click Save changes.
    10. Install the application into a production portal with access to the features that are required by the integration.
      • Under "Install URL (OAuth)", click Copy full URL to copy the installation URL for your application.
      • Navigate to the copied link in your browser. Select a standard account in which to install the application.
      • Click Connect app. You can close the resulting tab.

    Using a Private App

    To connect using a HubSpot private application token, set the AuthScheme property to "PrivateApp."

    You can generate a private application token by following the steps below:

    1. In your HubDB account, click the settings icon (the gear) in the main navigation bar.
    2. In the left sidebar menu, navigate to Integrations > Private Apps.
    3. Click Create private app.
    4. On the Basic Info tab, configure the details of your application (name, logo, and description).
    5. On the Scopes tab, select Read or Write for each scope you want your private application to be able to access.
    6. A minimum of hubdb and crm.objects.owners.read is required to access tables.
    7. After you are done configuring your application, click Create app in the top right.
    8. Review the info about your application's access token, click Continue creating, and then Show token.
    9. Click Copy to copy the private application token.

    To connect, set PrivateAppToken to the private application token you retrieved.

  9. Select HubDB tables and views that you want OData clients to access.
  10. Click Project -> Add New Item -> WCF Data Service.
  11. Specify the data source class and configure access to the new WCF Data Service. In the example below, the Access Rule for the entities is set to All. This means that any user will be able to read and modify data.

    using System; using System.Collections.Generic; using System.Data.Services; using System.Data.Services.Common; using System.Linq; using System.ServiceModel.Web; using System.Web; namespace HubDBService{ public class HubDBDataService : DataService<HubDBEntities> { public static void InitializeService(DataServiceConfiguration config) { config.SetEntitySetAccessRule("*", EntitySetRights.All); config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3; } } }
  12. Run the project. Applications that support OData can now access the Salesforce data and reflect any changes. You can access the feed in your browser. The feed will resemble the following:

Consume the OData Service from Power Pivot

You can now use the service from any OData client; for example, Excel Power Pivot.

  1. Open Excel and click on the Power Pivot Window button.
  2. A new pop-up will appear. Select the option From Data Feeds.
  3. In the resulting Table Import Wizard, enter the OData URL. For example, http://localhost:12449/HubDBDataService.svc/.
  4. After connecting to the OData service, click the Next button at the bottom of the window.
  5. A table listing of the available tables will appear in the next window of the wizard. Select which tables you want to import and click Finish.
  6. Click Close to import the data in Power Pivot.