I want to connect to a OPC UA Server via the Connect Method.
I am using the following code:
Code: Select all
EndpointDescription endpointDescription = new Discovery().GetMostSecureEndpoint(paramEndpoint);
//SecurityMode
switch (securityMode)
{
case "None":
endpointDescription.SecurityMode = MessageSecurityMode.None;
break;
case "Sign":
endpointDescription.SecurityMode = MessageSecurityMode.Sign;
break;
case "SignAndEncrypt":
endpointDescription.SecurityMode = MessageSecurityMode.SignAndEncrypt;
break;
}
//SecurityPolicy
endpointDescription.SecurityPolicyUri = @"http://opcfoundation.org/UA/SecurityPolicy#" + securityPolicy;
endpointDescription.TransportProfileUri = "http://opcfoundation.org/UA-Profile/Transport/uatcp-uasc-uabinary";
if (currentSession == null)
{
string key = "..."; //my licence key
byte[] keyArray = GetBytes(key);
ICertificate certificate = new Certificate(keyArray);
localSession.Application.AddCertificateToTrustList(certificate);
localSession.Application.ApplicationCertificate = certificate;
localSession.UserIdentity = new UserIdentity();
localSession.UserIdentity.Certificate = certificate;
}
localSession.SessionName = paramSessionName;
localSession.Connect(endpointDescription.EndpointUrl, SecuritySelection.BestAvailable);
But when I am using the licence for the certification as I do and set a new policy and mode, I get the exception: "Could not send an open secure channel request"
Can some one tell me, what I am doing wrong here ?
When starting my client I also setup the licence file via:
Code: Select all
ApplicationLicenseManager.AddProcessLicenses(System.Reflection.Assembly.GetExecutingAssembly(), "license.lic");
chauser