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.
Data Type | URL |
---|---|
Sales and Labor transactions | https://ecm-nsoewebservices-callaway.cbsnorthstar.com/reportservice/salesdata.svc |
Configuration data | https://ecm-nsoewebservices-callaway.cbsnorthstar.com/reportservice/configurationdata.svc |
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
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);
}
}
}
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"));
Register a handler to always provide a token with every request
_context.SendingRequest2 += OnSendingRequest;
Add token to request header when sending request