Data Access using OData

Data Service exposes DataMart tables via OData protocol.  This provides clients to write reports against their own data.  Each query requires an access token (from ECM) embedded in the header of the request.  The data returned from OData includes all sites under the account.

OData Service

Enter one of these URLs when adding a service reference.  



Demo System Access Token: wy39DVLSkXyG5ab2zrdCqtC65qLEqUeuk79EY7DgqTTUGPbFL63C9U2y

Demo System Site ID: C18BAB29-BEDA-4078-81D5-6791A2E17450

Demo System IP Address (to connect order entry iPad application): 67.113.166.226

Email: support@cbsnorthstar.com to request a Device PIN to unlock the order entry application and use the demo system. 

Sample Application Git Repository (on Bitbucket)

https://bitbucket.org/cbsnorthstar/northstar.dataservice.sampleapp

This contains sample code in both C# and Python.

How to connect our service references to Visual Studio



  1. Add a service reference to your project.



    Note: For first-time use with Microsoft.Data.OData on the dev machine, install DataService support from http://www.microsoft.com/en-us/download/details.aspx?id=39373


  2. Enter one of the above endpoints into the address bar and click Go.  Name the namespace of your service.  I named mine DataServiceOdata.

    If you're asked for authentication, you can click No.








    1. Once you've added the service reference, it will also download and reference the latest Data Service libraries.


    2. Note: If you are referencing the latest version of DataService OData, make sure the Microsoft Data Services references are v5.3.0 and up.  If they are not, follow these steps:

      1. Remove the Service Reference.

      2. Remove the above references along with the corresponding package references in packages.config.

      3. Install Microsoft Data Services version 5.3.0 and up.

      4. Repeat Step 1.

        1. The IDE will auto-reference the correct version of Microsoft Data Services.



  1. Install Microsoft.OData.ConnectedService.vsix for Visual Studio to auto-generate the metadata.

    1. This is a connected service to use older OData versions in newer Visual Studio.

  2. Once installed

    1. Right-click references and click Manage Connected Services




    2. Click OData Connected Services




    3. Name the service and add the service addresses one at a time, with different service names if using both.




    4. Service Address:

      1. Sales Data: https://ecm-nsoewebservices-callaway.cbsnorthstar.com/reportservice/salesdata.svc/$metadata

      2. Configuration Data:  https://ecm-nsoewebservices-callaway.cbsnorthstar.com/reportservice/configurationdata.svc/$metadata


    5. After the OData Connected service is added, you should see one or both of these with the references added.









  • Click File Explorer and search for DataSvcUtil.exe in Local Disk

  • Click Properties and look at Location

    • If same as above, do nothing

    • If different, replace the above location with the one you found

  • Run Developer Command Prompt for VS as Administrator

  • Change your directory to your project solution

  • Copy and paste the command

Add generated class into your solution

  • Open your solution in Visual Studios

  • Click Show All Files

  • Right-click your class and click Include In Project

  • Click Tools > NuGet Package Manager > Manage NuGet Packages for Solution

  • Search for Microsoft.Data.Services.Client and click Install

  • Add using System.Data.Services.Client to interact with the generated class

  • Add using Gops.Enterprise to use methods from the generated class



Test application in C# once service references are connected

Console Application
using Gops.Enterprise; using System; using System.Data.Services.Client; using System.Linq; namespace ConsoleApp { class Program { private static readonly string ACCESS_TOKEN = "wy39DVLSkXyG5ab2zrdCqtC65qLEqUeuk79EY7DgqTTUGPbFL63C9U2y"; private static readonly GOPS _context = new GOPS(new Uri("http://ecm-nsoewebservices-callaway.cbsnorthstar.com/reportservice/salesdata.svc")); static void Main(string[] args) { // Register handler on sending request. This will add the token in the header on every request. _context.SendingRequest2 += OnSendingRequest; // Query TimeRecords from OData var query = _context.TimeRecords.OrderByDescending(t => t.BusinessDate).Take(10); // This executes the query. var timeRecords = new DataServiceCollection<TimeRecord>(query); // The server may have a maximum number of records it will send. // For example, only the first 100 records may come down in the first query. // This while loop loads additional pages of data if necessary. // OData documentation: https://msdn.microsoft.com/en-us/library/dd942121.aspx // WCF documentation: https://msdn.microsoft.com/en-us/library/ee358709%28v=vs.110%29.aspx while (timeRecords.Continuation != null) { var nextPage = _context.Execute(timeRecords.Continuation); timeRecords.Load(nextPage); } foreach (var record in timeRecords) { Console.WriteLine("Name: {0} | Regular Hours: {1}", record.EmployeeFullName, record.RegularHours ?? 0); } _context.SendingRequest2 -= OnSendingRequest; Console.ReadKey(); } /// <summary> /// Added AccessToken to the header of each request /// </summary> /// <param name="sender"></param> /// <param name="e"></param> static void OnSendingRequest(object sender, System.Data.Services.Client.SendingRequest2EventArgs e) { e.RequestMessage.SetHeader("Authorization", "AccessToken=" + ACCESS_TOKEN); } } }



  1. Instantiate a new GOPS object with the actual service URL (not metadata)

    private static readonly GOPS _context = new GOPS(new Uri("http://ecm-nsoewebservices-callaway.cbsnorthstar.com/reportservice/salesdata.svc"));



  2. Register a handler to always provide a token with every request

    _context.SendingRequest2 += OnSendingRequest;



  3. Add token to request header when sending request