Professional OPC
Development Tools

logos

Online Forums

Technical support is provided through Support Forums below. Anybody can view them; you need to Register/Login to our site (see links in upper right corner) in order to Post questions. You do not have to be a licensed user of our product.

Please read Rules for forum posts before reporting your issue or asking a question. OPC Labs team is actively monitoring the forums, and replies as soon as possible. Various technical information can also be found in our Knowledge Base. For your convenience, we have also assembled a Frequently Asked Questions page.

Do not use the Contact page for technical issues.

How to set client certificate parameters; examples in VBA, VBScript, C#

More
06 Jul 2016 10:55 - 06 Jul 2016 11:00 #4198 by support
The default behavior of QuickOPC is to automatically generate a "subject name" for the instance certificate of the UA client application. QuickOPC then attempts to locate the certificate using this subject name in the certificate store, and if it finds such certificate, it uses it. If it does not find such certificate, it creates it and places it into the certificate store (so that it can be found next time, and not re-created).

If you want to provide your own certificate to be used by QuickOPC as UA client certificate, you either need to generate it with the subject name that QuickOPC uses (beware: it may change depending on conditions such as your assembly version and name!), or choose your own name, and instruct QuickOPC to use that name.

Here is an information on how to achieve it:
In general, you just need to set the ApplicationName property in EasyUAClient.SharedParameters.EngineParameters to the desired certificate subject. This can be directly in .NET, but because static properties are not supported in COM, it has to be done via the EasyUAClientConfiguration object in tools such as VBScript, VB6, VBA (Excel, ...), Delphi etc.

Code examples follow, and are also in attachments.

C#:
// Note that this only works once in each application domain. 
 
EasyUAClient.SharedParameters.EngineParameters.ApplicationName = "My Application";
EasyUAClient.SharedParameters.EngineParameters.ApplicationUriString = "http://opcua.demo-this.com/MyApplication";	// optional
 
// Do something - invoke an OPC read.
new EasyUAClient().ReadValue("http://opcua.demo-this.com:51211/UA/SampleServer", "nsu=http://test.org/UA/Data/;i=10853");
 
// The certificate will be located or created in a directory similar to:
// C:\Users\All Users\OPC Foundation\CertificateStores\UA Applications\certs\
// and its subject will be as given by the application name.


File Attachment:

File Name: Clientcert...ers.linq
File Size:1 KB



VBScript:
Rem This example demonstrates how to set the application name for the client certificate.
 
Option Explicit
 
' The configuration object allows access to static behavior.
Dim ClientConfiguration: Set ClientConfiguration = CreateObject("OpcLabs.EasyOpc.UA.EasyUAClientConfiguration")
 
' Set the application name, which determins the subject of the client certificate.
' Note that this only works once in each host process.
ClientConfiguration.SharedParameters.EngineParameters.ApplicationName = "QuickOPC - VBScript example application"
 
' Do something - invoke an OPC read.
Dim Client: Set Client = CreateObject("OpcLabs.EasyOpc.UA.EasyUAClient")
Dim value: value = Client.ReadValue("http://opcua.demo-this.com:51211/UA/SampleServer", "nsu=http://test.org/UA/Data/;i=10853")
 
' The certificate will be located or created in a directory similar to:
' C:\Users\All Users\OPC Foundation\CertificateStores\UA Applications\certs\
' and its subject will be as given by the application name.


File Attachment:

File Name: _EasyUAEng...Main.vbs
File Size:2 KB




VBA (in Excel):
Private Sub Workbook_Open()
    ' Sets the application name for the client certificate.
 
    ' The configuration object allows access to static behavior.
    Dim ClientConfiguration As New EasyUAClientConfiguration
 
    ' Set the application name, which determins the subject of the client certificate.
    ' Note that this only works once in each host process.
    ClientConfiguration.SharedParameters.EngineParameters.ApplicationName = "QuickOPC - VBA example application"
 
    ' Create EasyOPC-UA component
    Dim Client As New EasyUAClient
 
    ' Do something - invoke an OPC read.
    Range("A1").Value = Client.ReadValue("http://opcua.demo-this.com:51211/UA/SampleServer", "nsu=http://test.org/UA/Data/;i=10853")
 
    ' The certificate will be located or created in a directory similar to:
    ' C:\Users\All Users\OPC Foundation\CertificateStores\UA Applications\certs\
    ' and its subject will be as given by the application name.
End Sub



File Attachment:

File Name: UAClientCe...ters.xls
File Size:44 KB



Note: Some earlier QuickOPC versions had a bug which caused the changes to shared parameters be ignored. If you observe such problem, download QuickOPC 5.40.281.1 or later, and rebuild your project with the new assemblies.
Attachments:
Last edit: 06 Jul 2016 11:00 by support.

Please Log in or Create an account to join the conversation.

Moderators: support
Time to create page: 0.062 seconds