OPC Studio User's Guide and Reference
FindServerNode Method
Example 



OpcLabs.ServerOpcUA Assembly > OpcLabs.EasyOpc.UA Namespace > IEasyUAServerExtension Class : FindServerNode Method
The server object that will perform the operation.

The value of this parameter cannot be null (Nothing in Visual Basic).

The node descriptor to be searched for.

Because the UANodeDescriptor has implicit conversions from OpcLabs.EasyOpc.UA.AddressSpace.UANodeId, OpcLabs.EasyOpc.UA.AddressSpace.UANodeElement, OpcLabs.EasyOpc.UA.Navigation.UABrowsePath and System.String, in languages that support implicit conversion operators (such as C# or VB.NET), you can simply use a OpcLabs.EasyOpc.UA.AddressSpace.UANodeId object (representing the Id of the OPC UA node), a node element object (from OPC UA browsing), OpcLabs.EasyOpc.UA.Navigation.UABrowsePath object (representing OPC UA absolute browse path), or a string (with expanded node Id text) in place of this parameter, and the corresponding node descriptor will be constructed automatically. When the implicit conversion operators are not supported (such as with Python.NET), you can use the UANodeDescriptor.FromString, UANodeDescriptor.FromUABrowsePath, UANodeDescriptor.FromUANodeElement or UANodeDescriptor.FromUANodeId static method instead.

If you are using OPC Wizard (for server development), an implicit conversion from OpcLabs.EasyOpc.UA.NodeSpace.UAServerNode can be used in the same way to simply pass the server node in place of this parameter, which will use its OpcLabs.EasyOpc.UA.NodeSpace.UAServerNode.EffectiveNodeDescriptor property for the operation.

The value of this parameter cannot be null (Nothing in Visual Basic).

Attempts to find the node in the server that matches the specified node descriptor.
Syntax
'Declaration
 
<ExtensionAttribute()>
<CanBeNullAttribute()>
Public Shared Function FindServerNode( _
   ByVal server As IEasyUAServer, _
   ByVal nodeDescriptor As UANodeDescriptor _
) As UAServerNode
'Usage
 
Dim server As IEasyUAServer
Dim nodeDescriptor As UANodeDescriptor
Dim value As UAServerNode
 
value = IEasyUAServerExtension.FindServerNode(server, nodeDescriptor)
[Extension()]
[CanBeNull()]
public static UAServerNode FindServerNode( 
   IEasyUAServer server,
   UANodeDescriptor nodeDescriptor
)
[Extension()]
[CanBeNull()]
public:
static UAServerNode^ FindServerNode( 
   IEasyUAServer^ server,
   UANodeDescriptor^ nodeDescriptor
) 

Parameters

server
The server object that will perform the operation.

The value of this parameter cannot be null (Nothing in Visual Basic).

nodeDescriptor
The node descriptor to be searched for.

Because the UANodeDescriptor has implicit conversions from OpcLabs.EasyOpc.UA.AddressSpace.UANodeId, OpcLabs.EasyOpc.UA.AddressSpace.UANodeElement, OpcLabs.EasyOpc.UA.Navigation.UABrowsePath and System.String, in languages that support implicit conversion operators (such as C# or VB.NET), you can simply use a OpcLabs.EasyOpc.UA.AddressSpace.UANodeId object (representing the Id of the OPC UA node), a node element object (from OPC UA browsing), OpcLabs.EasyOpc.UA.Navigation.UABrowsePath object (representing OPC UA absolute browse path), or a string (with expanded node Id text) in place of this parameter, and the corresponding node descriptor will be constructed automatically. When the implicit conversion operators are not supported (such as with Python.NET), you can use the UANodeDescriptor.FromString, UANodeDescriptor.FromUABrowsePath, UANodeDescriptor.FromUANodeElement or UANodeDescriptor.FromUANodeId static method instead.

If you are using OPC Wizard (for server development), an implicit conversion from OpcLabs.EasyOpc.UA.NodeSpace.UAServerNode can be used in the same way to simply pass the server node in place of this parameter, which will use its OpcLabs.EasyOpc.UA.NodeSpace.UAServerNode.EffectiveNodeDescriptor property for the operation.

The value of this parameter cannot be null (Nothing in Visual Basic).

Return Value

Returns the server node that matches the given node descriptor, if such node exists. Otherwise, it returns null.

This method can return null (Nothing in Visual Basic).

Exceptions
ExceptionDescription

A null reference (Nothing in Visual Basic) is passed to a method that does not accept it as a valid argument.

This is a usage error, i.e. it will never occur (the exception will not be thrown) in a correctly written program. Your code should not catch this exception.

Remarks

This may be a time-consuming operation, especially when the address space is large. There are usually ways to achieve the same goal without having to search for the nodes by their node Id or browse path.

Only server nodes that your code has created are searchable in this way. This method is *not* a general facility to search for any node in the server.

This is an extension method (info: C#, VB.NET). In languages that have support for extensions methods (such as C# and VB.NET), you can use the extension method as if it were a regular method on the object that is its first parameter. In other languages (such as with Python.NET), you will call the extension as a static method, and pass it the object on which it acts as its first parameter.

Example
// This example shows how to search for nodes in the server by their node Id.
// You can use any OPC UA client, including our Connectivity Explorer and OpcCmd utility, to connect to the server. 
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
// OPC client, server and subscriber examples in C# on GitHub: https://github.com/OPCLabs/Examples-OPCStudio-CSharp .
// Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
// a commercial license in order to use Online Forums, and we reply to every post.

using System;
using OpcLabs.EasyOpc.UA;
using OpcLabs.EasyOpc.UA.NodeSpace;

namespace UAServerDocExamples._EasyUAServer
{
    class FindServerNode
    {
        public static void Main1()
        {
            // Instantiate the server object.
            // By default, the server will run on endpoint URL "opc.tcp://localhost:48040/".
            var server = new EasyUAServer();

            // Define some nodes in the server.
            UADataVariable constantDataVariable = UADataVariable.CreateIn(server.Objects, "Constant").ConstantValue("abc");
            UADataVariable nestedConstantDataVariable = UADataVariable.CreateIn(constantDataVariable, "NestedConstant").ConstantValue(42);
            
            // Try to find the nested constant data variable. It will be found.
            UAServerNode serverNode1 = server.FindServerNode("nsu=http://opclabs.com/OpcUA/Custom/Objects ;s=Constant.NestedConstant");
            Console.WriteLine(serverNode1);

            // Try to find an unknown server node. A null reference will be returned.
            UAServerNode serverNode2 = server.FindServerNode("nsu=http://opclabs.com/OpcUA/Custom/Objects ;s=Unknown");
            Console.WriteLine(serverNode2);
        }
    }
}
Requirements

Target Platforms: .NET Framework: Windows 10 (selected versions), Windows 11 (selected versions), Windows Server 2016, Windows Server 2022; .NET: Linux, macOS, Microsoft Windows

See Also