pkey
OPC UA

OPC UA Tutorial: How to Integrate Industrial Systems with .NET

Introduction

OPC UA (Open Platform Communications Unified Architecture) is the modern standard for industrial communication. It enables secure, platform-independent data exchange between machines, PLCs, SCADA systems, and enterprise applications.

If you’re building industrial software in .NET, OPC UA is often the backbone of your integration layer.

This tutorial walks through:

  • How OPC UA works
  • Real architecture in production systems
  • Step-by-step .NET implementation
  • Best practices for industrial environments

What is OPC UA?

OPC UA is a machine-to-machine communication protocol designed for industrial automation.

It replaces older OPC standards by adding:

  • Platform independence
  • Built-in security (encryption, certificates)
  • Structured data models
  • Scalability (from PLC to cloud)

OPC UA Architecture

https://images.openai.com/static-rsc-4/F_hXyPE74Gc_eg44mqXtNtsBrsyM8nd00MRcKOqd62W3O7j6f2yOLggSvHCFf5swz5MIzhCRjVqZ1ddOkGCspTsPSmpK4PcDHLvUitgtuTIZPiE5_vZjt0SE4s7OW0_HakdcZBYoxlw5DNSFAIFxRjlTxa2RJPcusQ-v0-FiqIAHhJNY0g6J6XLNJJBgSokb?purpose=fullsize
https://images.openai.com/static-rsc-4/Nxf-2dzndcvSTzqcI6RplyBN7x98MSLExvztj7PEdZb5W3tsLajweZY21_ylCz-QmwjhduA0yAKfujBLzcrafXAkDGSiYjAXFweIJDIP0UWIB5ReUdAEHbT_DaPuyV4_MgZuwGlRCeapakUkR_hYL4CCaLNQp9ylLcas9x-tQlY58otJEeDd05oyIgTfSNYe?purpose=fullsize
https://images.openai.com/static-rsc-4/i_Lq8D9lznLmfQNFhwDrBQ5K20XqN84qQs37VOYmwmiJVGfoQ5L8ILUzH-FEr0Chh5mi21Ujlo5-iTFw-aHvpzqKGBSigLfEIuzGcb_WRs4UWg4ob_xsXn4FwOSjfxSVWhSC5wnVXur1EfKdJVNymaGZw6JV8t2VNTYVOwF2dOCuk_077zDUaNOIj_PmpdeV?purpose=fullsize

7

Key Components

  • OPC UA Server
    • Exposes data (PLC, SCADA, sensors)
  • OPC UA Client
    • Reads/writes data (.NET app, MES, ERP)
  • Address Space
    • Structured data model (nodes, variables)
  • Transport Layer
    • TCP / HTTPS

Real Production Flow

In a real factory setup:

  1. PLC collects machine data
  2. OPC UA Server exposes variables
  3. .NET application reads data
  4. Data is processed and stored
  5. MES/ERP consumes results

Example Data Flow

https://images.openai.com/static-rsc-4/f5jsgb_iSvGiP71iSXIdvSsA2i4dieUsQ2LfavTZHc1TA6U-Sbk7gq0Kg2tsIZPry0bFaH4KAw_kTVEsqBfj2GAVWQWoert3bvSnjn-iGZctewutUMK5mZmN5vqj_K4_IZDO1C9ToTHGu6ZYzhU6AYiZUkSFpCzWZCeeKumxp8E76cVQMgOcALSQk0ia-TL_?purpose=fullsize
https://images.openai.com/static-rsc-4/dxaPZz5Gr2CDxAyHA-q9cAhXIKKPa6ASlti-f9InYzVKIuPrnjy_CQNFRzJSVy4l7tsukdjjy9wP-FO9WTK70C1dtCOY7NTwA91zlB4vjcRJekk455E74pmhPym2ffrII0i3H6_QjBBl7LVqki0obxQQcicVR872kG-vD0YPiATZD5qwU0ZJyXVoV_rlqhjU?purpose=fullsize
https://images.openai.com/static-rsc-4/kVY7F9jYBQeOTRYb-ckyruapJpToP6XOJdSfgZGTp58NNRz7cZF2qYZZ92Q0PhvQnGuDeCGC5gRtV5c4d7feBMfhV1XjSkyGe8DiKeBIgV7Th9OFTrUl1L-7UpsSFJvZDnq3K7pc8GhIrJ-X0nJtEB3PTKG4FH2LvcFqzQxk5CxccYJE0vCpzdEc0M5_dhbR?purpose=fullsize

6


Step 1: Install OPC UA in .NET

Run:

C#
dotnet add package OPCFoundation.NetStandard.Opc.Ua

Step 2: Basic OPC UA Client in C#

Below is a minimal working example.

C#
using Opc.Ua;
using Opc.Ua.Client;
using Opc.Ua.Configuration;public class OpcUaClient
{
    public async Task ReadValue()
    {
        var config = new ApplicationConfiguration
        {
            ApplicationName = "OpcUaClient",
            ApplicationType = ApplicationType.Client,
            SecurityConfiguration = new SecurityConfiguration
            {
                AutoAcceptUntrustedCertificates = true
            },
            TransportConfigurations = new TransportConfigurationCollection(),
            TransportQuotas = new TransportQuotas { OperationTimeout = 15000 },
            ClientConfiguration = new ClientConfiguration()
        };        await config.Validate(ApplicationType.Client);        var endpoint = CoreClientUtils.SelectEndpoint("opc.tcp://localhost:4840", false);
        var endpointConfig = EndpointConfiguration.Create(config);
        var configuredEndpoint = new ConfiguredEndpoint(null, endpoint, endpointConfig);        using var session = await Session.Create(
            config,
            configuredEndpoint,
            false,
            "OPC UA Session",
            60000,
            null,
            null);        var nodeId = new NodeId("ns=2;s=Machine/Temperature");        var value = session.ReadValue(nodeId);        Console.WriteLine($"Temperature: {value.Value}");
    }
}

Step 3: Connecting to PLC (Siemens Example)

https://images.openai.com/static-rsc-4/uqPmXaI69BUa8bmwXP4wA74nP_rpc-XXYwQ1YfjcCZWWsTpi_9EXsd1nNh68UEEwAUQbPrZl6tho_tXYSPlCzOW408WWkNA2xRK8G932HoOoMUbTGREO6DtZ5OzF6027IM2dip_nKiNCSBQiY3CZvQdwInyP9UuqZxWOT_XAf_k_c9qDJ51ae9mlcDnYQ4Ay?purpose=fullsize
https://images.openai.com/static-rsc-4/jKwzDSPrJJjDmxQ1I0mlQpXLZCrBPbA7RFsuJBj7FIl5j2QswXDohDD6wda_xJN3yecOpc2WeIdjEkqn8h0xdqxY0ftLYuQwg5dZll9Y4nDwMqUL3JrWCAxXTC0MDN-C1HSlwC-c6cXDoqAB4QQuLbYCePX9bIYSloD8kEuHWMRzwXNAQ-FXV7VSEHG0R30T?purpose=fullsize
https://images.openai.com/static-rsc-4/569qyC7ke0NVo15GMX_e9rc9-mawuFOFlwf6d2AjX4RYCqnMrbFdkJMiB7e48VT5XUBoys0ULYBMdyjI9JVrqko9kozL5nc9qBL7FbwqtuS9e85EicEzxOuKwVmRikLx3G0GPgK8zvO3tT1Ekuud2guG6wM_vwnNJTMi7IpFPAX9cIoyB3bmpJHvVvCOPmFj?purpose=fullsize

8

Steps:

  1. Enable OPC UA Server in PLC (e.g. Siemens S7-1500)
  2. Configure endpoint (e.g. opc.tcp://192.168.0.10:4840)
  3. Define exposed variables
  4. Import certificate in client

Step 4: Subscriptions (Real-Time Data)

Polling is inefficient. OPC UA supports subscriptions.

C#
var subscription = new Subscription(session.DefaultSubscription)
{
    PublishingInterval = 1000
};var monitoredItem = new MonitoredItem(subscription.DefaultItem)
{
    StartNodeId = new NodeId("ns=2;s=Machine/Speed"),
    AttributeId = Attributes.Value,
    SamplingInterval = 1000
};monitoredItem.Notification += (monitoredItem, e) =>
{
    foreach (var value in monitoredItem.DequeueValues())
    {
        Console.WriteLine($"Speed: {value.Value}");
    }
};subscription.AddItem(monitoredItem);
session.AddSubscription(subscription);
subscription.Create();

OPC UA vs SCADA vs Direct PLC Access

ApproachProsCons
Direct PLCFastVendor lock
SCADAVisualizationLimited integration
OPC UAStandardized, secureSlight overhead

Security in OPC UA

OPC UA includes:

  • Encryption (TLS)
  • Certificates
  • Authentication
  • User roles

Important in production:

  • Never use AutoAcceptUntrustedCertificates = true
  • Use signed certificates
  • Restrict endpoints

Best Practices

1. Use Subscriptions, not Polling

Better performance and scalability.

2. Separate Integration Layer

Create dedicated service:

  • OpcUaService
  • DataProcessor
  • EventPublisher

3. Use Message Broker

Combine OPC UA with:

  • RabbitMQ
  • Kafka

Flow:

PLC → OPC UA → .NET → Queue → Microservices

Advanced Architecture (Enterprise)

https://images.openai.com/static-rsc-4/Y-MG-v-XjyHfSYXXkNBK7LxhDwOjfU96VgYYPlzD_C-m2Q-bwSG_WPSq36DkvCfvx7g3iiXkCpOlio-95coIKY6HsCwqLLfdaZptTXD6qb002JIgAX7QUBZ7WsFiGoQGOe4KGEo4n1IIlGZMwMLljJCOwtlV0kvjq5pDB02ul1ZwciVVgii1w3_yaP297VAy?purpose=fullsize
https://images.openai.com/static-rsc-4/8IZg3TNMLhG_GYKD1q7W-Q5PreIQroTAG2y70DaODiBzt5oXxiBcOcf0BGNvxsnrP6DMpDE9FgLKe6MK3mqAUjEsDLTZJ8J_rW5_pnjwLg9XZOpk_-mj6sDd6OnhpczOXrEMNChOiZg3MpAU09m5PBqaYGIP3tIKJzrC2wVrKxHX26KGLClzyomISfEVJvZW?purpose=fullsize
https://images.openai.com/static-rsc-4/fCcablSmQkIlqCtUhIZhFTYVWn0NT6TsYGM4C7FvIQRYzlMWhHWinoc64A67-ysO3rdkVDCn3Z13sxzPtpkK8kMiZCfAxMf_TjjlQzOVqe-DsAxpvf1-Qa5kA614X0I2xvjtp10QD17ByuCrxqvcTJ81y02Q3YzObze4sTfrrYDhrXJeaPALls5SmpcU2Vu6?purpose=fullsize

6


Common Problems

Connection issues

  • Firewall blocks port 4840
  • Certificate mismatch

Performance

  • Too many nodes subscribed
  • High sampling rate

Debugging

  • Use OPC UA client tools:
    • UA Expert

When to Use OPC UA

Use OPC UA when:

  • You integrate multiple PLC vendors
  • You need secure communication
  • You build scalable industrial systems

Avoid when:

  • Simple single-device communication
  • Ultra-low latency (<1ms required)

Conclusion

OPC UA is the industry standard for modern industrial communication.

For .NET developers, it provides:

  • Clean integration layer
  • Scalability
  • Security
  • Vendor independence

If you’re building industrial or manufacturing systems, OPC UA is not optional — it’s foundational.


References

https://opcfoundation.org

https://www.unified-automation.com/products/development-tools/uaexpert.html

More Info

We implement this in real production systems.
If you need help → contact us

Contact