In my custom C# console App (.Net Framework) (using the evaluation license), the MissingApplicationCertificate event is not being raised.
I have used License and App.Config files from GettingStarted sample project. I have also copied the Opc.Ua.CertificateGenerator.exe into the application output directory .i.e. next to the application exe.
The App.config file mentions below:
Code: Select all
<!-- Specify location of Certificates and Trust Lists -->
<ApplicationCertificate>
<StoreType>Directory</StoreType>
<StorePath>%CommonApplicationData%\unifiedautomation\UaSdkNetBundleEval\pkiclient\own</StorePath>
<!--
<StoreType>Windows</StoreType>
<StorePath>LocalMachine\My</StorePath>
-->
Below is my code:
Code: Select all
namespace OPCUAExplorer
{
static class Program
{
static void Main(string[] args)
{
try
{
ApplicationLicenseManager.AddProcessLicenses(System.Reflection.Assembly.GetExecutingAssembly(), "License.lic");
//Create the certificate if it does not exist yet
ApplicationInstance.Default.AutoCreateCertificate = true;
//Breakpoint #1
ApplicationInstance.Default.MissingApplicationCertificate +=
new CreateCertificateEventHandler(Application_MissingApplicationCertificate);
//SERVER AND ENDPOINT DISCOVERY[WORKS]
//========================================
List<ApplicationDescription> servers;
List<EndpointDescription> endpoints;
// create the object used to find servers or endpoints.
using (Discovery discovery = new Discovery())
{
// look for the LDS with the default endpoint.
//string discoveryUrlServer = "opc.tcp://" + "localhost" + ":4840";
//servers = discovery.FindServers(discoveryUrlServer);
// get the discoverUrl from the gui
string discoveryUrlEndPoints = "opc.tcp://localhost:48030"; //UADemoServer
// look for the LDS with the default endpoint.
endpoints = discovery.GetEndpoints(discoveryUrlEndPoints);
}
}
catch (Exception e)
{
Console.Write(e.Message);
return;
}
}
static void Application_MissingApplicationCertificate(object sender, CreateCertificateEventArgs e)
{
try
{
// let the application create a suitablable default if no user interaction allowed.
if (e.Silent)
{
return;
}
//Breakpoint #2
Console.Write("Missing Certificate");
}
catch (Exception exception)
{
Console.Write(exception.Message);
}
}
}
}