GodSharp.Opc.Ua.Server

Opc Sample


GodSharp.Opc.Ua.Server

Azure DevOps builds (main)

Package Version

Name NuGet MyGet
GodSharp.Opc.Ua.Common NuGet MyGet
GodSharp.Opc.Ua.Client NuGet MyGet
GodSharp.Opc.Ua.ProxyServer NuGet MyGet
GodSharp.Opc.Ua.Server NuGet MyGet
GodSharp.Opc.Ua.Server.AspNetCore NuGet MyGet
GodSharp.Opc.Ua.ComplexTypes NuGet MyGet

Introduction

Package Uasge
GodSharp.Opc.Ua.Common a opc ua common lib
GodSharp.Opc.Ua.Client a opc ua client
GodSharp.Opc.Ua.ProxyServer a proxy for opc ua server
GodSharp.Opc.Ua.Server a opc ua server
GodSharp.Opc.Ua.Server.AspNetCore opc ua server for asp.net core
GodSharp.Opc.Ua.ComplexTypes custom generate encode/decode method for EncodeableObject class

Getting Started

  PM> Install-Package GodSharp.Opc.Ua.Server

Configuration

  // Auto Generate ApplicationConfigurationFile
  GodSharp.Opc.Ua.OpcUaHelper.GenerateApplicationConfigurationFile =  true;
  
  // Configuration for UA Server
  ApplicationConfiguration? configuration = null;
  configuration = await   GodSharp.Opc.Ua.OpcUaHelper.ServerConfigurationAsync(
      "GodSharpOpcUaServer",
      "GodSharp Opc Ua Server",
      new string[] { Utils.Format(@"opc.tcp://{0}:4840", "localhost") }
      //,(s, e) => CertificateValidationHandler(configuration, s, e)
      , CertificateValidationHandler
      );
  
  // Instance UA Server
  var server = new OpcUaStandardServer(new  SampleServerAuthorizationFilter ());
  
  // Start server
  server.Start(configuration);

Instance

  // Instance UA Server
  var server = new OpcUaStandardServer(new  SampleServerAuthorizationFilter ());
  
  // Start server
  server.Start(configuration);
  
  // Stop server
  server.Stop();

ServerAuthorizationFilter

Used to authorized user token.

  public class SampleServerAuthorizationFilter :   IServerAuthorizationFilter
  {
      public ServerAuthorizationResult Verify(UserNameIdentityToken  token)
      {
          string userName = token.UserName;
          string decryptedPassword = token.DecryptedPassword;
          if (userName == "admin" && decryptedPassword ==   "admin@password")
          {
              return new ServerAuthorizationResult(Authorized: true,   Administrator: true);
          }
  
          if (userName == "user" && decryptedPassword == "user@password")
          {
              return new ServerAuthorizationResult(Authorized: true);
          }
  
          return new ServerAuthorizationResult(Authorized: false);
      }
  }

License

Free!