We have issue using a server endpoint with SecurityMode 'None' and SecurityPolicy "None" that requires client to provide username/password identity.
An internal "System.NullReferenceException" is thrown by QuickOPC.
We don't have that issue with endpoints that use different security policy or anonymous identity.
Code:
<ServerSecurityPolicy>
<SecurityMode>None_1</SecurityMode>
<SecurityPolicyUri>http://opcfoundation.org/UA/SecurityPolicy#None</SecurityPolicyUri>
</ServerSecurityPolicy>
</SecurityPolicies>
<UserTokenPolicies>
<ua:UserTokenPolicy>
<ua:TokenType>UserName_1</ua:TokenType>
</ua:UserTokenPolicy>
</UserTokenPolicies>
Code:
var opcClient = new EasyUAClient() { Isolated = true };
var sessionParameters = opcClient.IsolatedParameters.SessionParameters;
sessionParameters.EndpointSelectionPolicy.AllowedMessageSecurityModes = OpcLabs.EasyOpc.UA.Engine.UAMessageSecurityModes.SecurityNone;
sessionParameters.EndpointSelectionPolicy.SecurityPolicyUri = new Uri("http://opcfoundation.org/UA/SecurityPolicy#None");
sessionParameters.UserIdentity.UserNameTokenInfo = new UserNameTokenInfo(_clientConfiguration.Username, _clientConfiguration.Password);
var endpointDescriptor = new UAEndpointDescriptor(_clientConfiguration.EndpointUrl);
var res = opcClient.BrowseDataNodes(endpointDescriptor);
Code:
2021-02-15 17:32:05.970 [VRB] EasyUAClient Information OPCLabs-UAEngine: The OPC-UA engine will resolve the client instance certificate parameters directory store path to "C:\ProgramData\OPC Foundation\CertificateStores\MachineDefault".
2021-02-15 17:32:06.010 [VRB] EasyUAClient Information OPCLabs-UAEngine: The OPC-UA engine has determined the application configuration parameters as listed below.
ProductUri: urn:literal:string:GenericTestTool
2021-02-15 17:32:06.078 [VRB] EasyUAClient Information OPCLabs-EasyUAClient: Licensing for EasyUAClient component started, license serial number *******, issuer name "OPC Labs", subject name "***************".
2021-02-15 17:32:06.268 [VRB] EasyUAClient Information OPCLabs-UAEngine: External information from "InteractionProviderCompositor" (0,1): Newly selected interaction handler is 'Console'.
2021-02-15 17:32:06.329 [VRB] EasyUAClient Information OPCLabs-UAEngine: The OPC-UA engine has successfully connected to the underlying subsystems.
2021-02-15 17:32:06.444 [VRB] EasyUAClient Information OPCLabs-UAEngine: The OPC-UA client session with connect sequence number 1 is connecting to endpoint URL "opc.tcp://localhost:9090/GenericSimulator".
2021-02-15 17:32:06.468 [VRB] EasyUAClient Information OPCLabs-UAEngine: The OPC-UA client session with connect sequence number 1 has synthesized an OPC-UA endpoint (without preselection) with following parameters:
Endpoint URL "opc.tcp://localhost:9090/GenericSimulator", message security mode 'None', security policy URI "http://opcfoundation.org/UA/SecurityPolicy#None", transport profile URI ", server certificate presented: no, use binary encoding: yes.
2021-02-15 17:32:06.733 [VRB] EasyUAClient Information OPCLabs-UAEngine: OPC-UA endpoint selection on discovery URL "opc.tcp://localhost:9090/GenericSimulator" candidate report (1 entries) follows.
[0:Winner(1000+0)].
2021-02-15 17:32:06.743 [VRB] EasyUAClient Information OPCLabs-UAEngine: The OPC-UA client session with connect sequence number 1 user token selection on endpoint URL "opc.tcp://localhost:9090/GenericSimulator" candidate report (1 entries) follows.
[0:Winner("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0")].
2021-02-15 17:32:06.745 [VRB] EasyUAClient Information OPCLabs-UAEngine: The OPC-UA client session with connect sequence number 1 on endpoint URL "opc.tcp://localhost:9090/GenericSimulator" has been associated with user identity token type 'UserName', display name "qqqq".
2021-02-15 17:32:06.773 [VRB] EasyUAClient Error OPCLabs-UAEngine: INTERNAL ERROR. The OPC-UA engine might be in an unstable state.
An exception of type "System.NullReferenceException" from source "Opc.Ua.Core" has occurred in OPC-UA SDK action 'static Session.Create'. The exception descend follows.
(1) {System.NullReferenceException} Opc.Ua.Core(GetPlainTextBlockSize) -> Object reference not set to an instance of an object.
2021-02-15 17:32:06.781 [VRB] EasyUAClient Warning OPCLabs-UAEngine: The OPC-UA client session with connect sequence number 1 failed to connect to endpoint URL "opc.tcp://localhost:9090/GenericSimulator".
INTERNAL ERROR. An exception of type "System.NullReferenceException" from source "Opc.Ua.Core" has occurred in OPC-UA SDK action 'static Session.Create'. The exception descend follows.
(1) {System.NullReferenceException} Opc.Ua.Core(GetPlainTextBlockSize) -> Object reference not set to an instance of an object.
+ Following (15) events were gathered during the action on activity ID [3], in the order of first occurrence:
SDK trace: CreateSession Called. RequestHandle=1, PendingRequestCount=1
[4] SDK trace: Token #0 created. CreatedAt = 15:32:06.611 . Lifetime = 3600000
[4] SDK trace: Token #1 activated. CreatedAt = 15:32:06.611 . Lifetime = 3600000
SDK trace: CreateSession Completed. RequestHandle=1, PendingRequestCount=0
SDK trace: Revised session timeout value: 600000.
SDK trace: Max response message size value: 4194304. Max request message size: 4194304
SDK trace: Server signature is null or empty.
SDK trace: CloseSession Called. RequestHandle=2, PendingRequestCount=1
SDK trace: CloseSession Completed. RequestHandle=2, PendingRequestCount=0
[7] SDK trace: TCPCLIENTCHANNEL SOCKET CLOSED: 00000B0C, ChannelId=1
Exception: {Opc.Ua.ServiceResultException} BadSecureChannelClosed
SDK trace: CloseSession Called. RequestHandle=3, PendingRequestCount=1
2*Exception: {System.ObjectDisposedException} Cannot access a disposed object.
SDK trace: CloseSession Completed. RequestHandle=3, PendingRequestCount=0, StatusCode=Bad
+ Events starting with activity ID in [] may not necessarily be related to the current action.
2021-02-15 17:32:06.783 [VRB] EasyUAClient Information OPCLabs-UAEngine: The OPC-UA client session on endpoint URL "opc.tcp://localhost:9090/GenericSimulator" failed at tick 6651770453 and will retry in 10000 milliseconds.
2021-02-15 17:32:06.791 [VRB] EasyUAClient Warning OPCLabs-UAEngine: The status subscription for an OPC-UA session on endpoint URL "opc.tcp://localhost:9090/GenericSimulator" is in failure. Further such warnings on this session will not be logged.
INTERNAL ERROR. An exception of type "System.NullReferenceException" from source "Opc.Ua.Core" has occurred in OPC-UA SDK action 'static Session.Create'. The exception descend follows.
(1) {System.NullReferenceException} Opc.Ua.Core(GetPlainTextBlockSize) -> Object reference not set to an instance of an object.
+ Following (15) events were gathered during the action on activity ID [3], in the order of first occurrence:
SDK trace: CreateSession Called. RequestHandle=1, PendingRequestCount=1
[4] SDK trace: Token #0 created. CreatedAt = 15:32:06.611 . Lifetime = 3600000
[4] SDK trace: Token #1 activated. CreatedAt = 15:32:06.611 . Lifetime = 3600000
SDK trace: CreateSession Completed. RequestHandle=1, PendingRequestCount=0
SDK trace: Revised session timeout value: 600000.
SDK trace: Max response message size value: 4194304. Max request message size: 4194304
SDK trace: Server signature is null or empty.
SDK trace: CloseSession Called. RequestHandle=2, PendingRequestCount=1
SDK trace: CloseSession Completed. RequestHandle=2, PendingRequestCount=0
[7] SDK trace: TCPCLIENTCHANNEL SOCKET CLOSED: 00000B0C, ChannelId=1
Exception: {Opc.Ua.ServiceResultException} BadSecureChannelClosed
SDK trace: CloseSession Called. RequestHandle=3, PendingRequestCount=1
2*Exception: {System.ObjectDisposedException} Cannot access a disposed object.
SDK trace: CloseSession Completed. RequestHandle=3, PendingRequestCount=0, StatusCode=Bad
+ Events starting with activity ID in [] may not necessarily be related to the current action.
2021-02-15 17:32:09.835 [ERR] An error occured while initializing client
OpcLabs.EasyOpc.UA.OperationModel.UAException: An OPC-UA operation failure with error ID 'OpcLabs.BaseLib.Portable.CustomException' occurred, originating from 'Opc.Ua.Core' and with depth of 2. The inner exception, of type "OpcLabs.BaseLib.Portable.CustomException", contains details about the problem. ---> OpcLabs.BaseLib.Portable.CustomException: INTERNAL ERROR. An exception of type "System.NullReferenceException" from source "Opc.Ua.Core" has occurred in OPC-UA SDK action 'static Session.Create'. The exception descend follows.
(1) {System.NullReferenceException} Opc.Ua.Core(GetPlainTextBlockSize) -> Object reference not set to an instance of an object.