How have the root node in a session?

Questions regarding the use of the .NET SDK 2.0 for Server or Client development or integration into customer products ...

Moderator: uasdknet

Post Reply
lionel
Jr. Member
Jr. Member
Posts: 3
Joined: 16 Sep 2015, 14:54

How have the root node in a session?

Post by lionel »

Hi

I would like to know how to get the root node from a defined namespace?
Actually I know the namespace ID and my session is well connected.

My goal is to browse all the hierarchy from the root node.

Tanks in advance for your answers.

User avatar
Support Team
Hero Member
Hero Member
Posts: 3068
Joined: 18 Mar 2011, 15:09

Re: How have the root node in a session?

Post by Support Team »

Hi,

Namespaces do not need to have specific root nodes.
Some companion specifications define entry points (like the Devices folder in http://opcfoundation.org/UA/DI/). If such an entry point is well known to a client, the client can use them as "root node for the namespace".
In general a client needs to browse recursivly through the address space starting at the RootFolder (ObjectIds.RootFolder) if a specific namespace should be explored.

Best regards
Support Team

lionel
Jr. Member
Jr. Member
Posts: 3
Joined: 16 Sep 2015, 14:54

Re: How have the root node in a session?

Post by lionel »

Hi

tanks for your answer.

But i don't know how to browse recursivly with the RootFolder. Have you a example code?
Is not it difficult to browse through several namespace?

tanks

Best regards

Lionel

User avatar
Support Team
Hero Member
Hero Member
Posts: 3068
Joined: 18 Mar 2011, 15:09

Re: How have the root node in a session?

Post by Support Team »

Hi,

Code: Select all

static void BrowseRec(Session session, NodeId nodeId, SortedList<NodeId, NodeId> browsedNodes)
{
    var Browse = new Action<List<ReferenceDescription>>(a =>
    {
        foreach (ReferenceDescription refernce in a)
        {
            NodeId targetNodeId = refernce.NodeId.ToNodeId(session.NamespaceUris);
            if (!browsedNodes.ContainsKey(targetNodeId))
            {
                browsedNodes.Add(targetNodeId, targetNodeId);
                BrowseRec(session, targetNodeId, browsedNodes);
            }
        }
    });

    byte[] continuationPoint;
    List<ReferenceDescription> results = session.Browse(nodeId, out continuationPoint);
    Browse(results);

    while (continuationPoint != null)
    {
        results = session.BrowseNext(ref continuationPoint);
        Browse(results);
    }
}
Best regards
Support Team

MrIS
Full Member
Full Member
Posts: 7
Joined: 19 Jul 2018, 10:30

Re: How have the root node in a session?

Post by MrIS »

Support Team wrote:
05 Oct 2015, 11:12
Hi,

Code: Select all

static void BrowseRec(Session session, NodeId nodeId, SortedList<NodeId, NodeId> browsedNodes)
{
    var Browse = new Action<List<ReferenceDescription>>(a =>
    {
        foreach (ReferenceDescription refernce in a)
        {
            NodeId targetNodeId = refernce.NodeId.ToNodeId(session.NamespaceUris);
            if (!browsedNodes.ContainsKey(targetNodeId))
            {
                browsedNodes.Add(targetNodeId, targetNodeId);
                BrowseRec(session, targetNodeId, browsedNodes);
            }
        }
    });

    byte[] continuationPoint;
    List<ReferenceDescription> results = session.Browse(nodeId, out continuationPoint);
    Browse(results);

    while (continuationPoint != null)
    {
        results = session.BrowseNext(ref continuationPoint);
        Browse(results);
    }
}
Best regards
Support Team
Hi there,

I know that's old topic, but algorithm you provided should be still valid or at least the idea of recursive calling Browse method.
I have tried out this function but unfortunately it throws BadSessionIdInvalid exception. Before raising this exception it can browse for approx. 30 nodes in average. I think that exception is related to session timeout, I tried to extend value in OperationTimeout property of RequestSettings object without any success.

Do you have any ideas what could help me to overcome this limit, what to set up properly, or something similar.
Thanks in advance.

User avatar
Support Team
Hero Member
Hero Member
Posts: 3068
Joined: 18 Mar 2011, 15:09

Re: How have the root node in a session?

Post by Support Team »

Hello,

In most scenarios the default values for the Session and operation timeouts are good, so you should not change them before analysing the trace file of your client. You should also create a wireshark capture and analyse which service call is causing the exception / returning the ServiceFault message.
Best regards
Unified Automation Support Team

Post Reply