Please ensure Javascript is enabled for purposes of website accessibility
Powered by Zoomin Software. For more details please contactZoomin

AVEVA™ Integration Service

Getting Started

  • Last UpdatedJun 24, 2025
  • 2 minute read

Initialization of DataApiClient:

internal class Config

{

public static string token = "<connnect service access token>";

}

private const string ApiUrl = "https://eu.ais.connect.aveva.com/data";

private const string DatasourceName = "UE-APS-Datasource";

private const string TopicName = "customtopic";

private const string TableName = "table1";

var client = new DataApiClient(ApiUrl, AuthenticationType.Connect, 60, Config.token);

Setup PubSub client

Initializes the SignalR PubSub client and sets up event handlers for connection and message notifications.

var pubsubClient = await InitializePubSubClient(); // Initializes the PubSub client for real-time notifications

private static async Task<SignalRPubSubClient> InitializePubSubClient()

{

var pubsubClient = await SignalRHubConnectionFactory.CreatePubSubClient(

null,

new HubConnectionManager(),

AuthenticationType.Connect,

ApiUrl,

Config.token,

null

);

pubsubClient.ConnectionEst += PubsubClient_ConnectionEst;

pubsubClient.MessagePublished += PubsubClient_MessagePublished;

return pubsubClient;

}

// Event handler for PubSub connection established

private static void PubsubClient_ConnectionEst(object? sender, EventArgs e)

{

System.Console.WriteLine("PubSub connection established successfully!");

}

// Event handler for PubSub message received

private static void PubsubClient_MessagePublished(object? sender, PubSubMessageEventArgs e)

{

System.Console.WriteLine($"Real-time notification received:");

System.Console.WriteLine($" - Data Source: {e.PubSubMessage.Datasource}");

System.Console.WriteLine($" - Topic: {e.PubSubMessage.Topic}");

System.Console.WriteLine($" - Context: {e.PubSubMessage.Context}");

}

List of Data Sources

Retrieves a list of data sources.

await ListDataSources(client); // Lists all available data sources

private static async Task ListDataSources(DataApiClient client)

{

var datasources = await client.GetDataSources();

if (datasources != null && datasources.Tables.Count > 0)

{

System.Console.WriteLine("Available data sources:");

foreach (DataTable table in datasources.Tables)

{

foreach (DataRow row in table.Rows)

{

System.Console.WriteLine($" - {row["ProductCategory"]}: {row["Name"]}");

}

}

}

else

{

System.Console.WriteLine("No data sources found.");

}

}

Subscribe to Topic

await pubsubClient.Subscribe(TopicName);

// Publish Sample Data

// Creates a DataTable with dummy data and publishes it to a data source table.

var acknowledgementId = await PublishSampleData(client);

// Creates and publishes sample data to the specified data source and table

private static async Task<string> PublishSampleData(DataApiClient client)

{

// Create sample table with data

var table = new DataTable();

table.Columns.Add("ID", typeof(int));

table.Columns.Add("Name", typeof(string));

table.Columns.Add("Date", typeof(DateTime));

// Add rows with sample data

for (int i = 1; i <= 10; i++)

{

table.Rows.Add(i, $"Sample_{i}", DateTime.Now);

}

// Post data to the table and get response

var response = await client.PostTableData(

DatasourceName,

TableName,

table,

"",

"",

TopicName

);

return response.AcknowledgementId;

}

Retrieve Published Data

Retrieves data using an acknowledgement ID after publishing

await GetPublishedData(client, acknowledgementId);

private static async Task GetPublishedData(DataApiClient client, string acknowledgementId)

{

var response = await client.GetTableDataByAcknowledgementId(DatasourceName, acknowledgementId);

WriteDataTableToConsole(response);

}

private static void WriteDataTableToConsole (DataTable table)

{

if (table == null || table.Rows.Count == 0)

{

System.Console.WriteLine("The DataTable is empty.");

return;

}

// Print column headers

foreach (DataColumn column in table.Columns)

{

System.Console.Write($"{column.ColumnName}\t");

}

System.Console.WriteLine();

// Print rows

foreach (DataRow row in table.Rows)

{

foreach (var item in row.ItemArray)

{

System.Console.Write($"{item}\t");

}

System.Console.WriteLine();

}

}

In This Topic
Related Links
TitleResults for “How to create a CRG?”Also Available in