.NET Based OPC UA Client/Server SDK
Read – Read Attribute


A session with the server must be established.


The following dialog shows an example implementation of the Read service which allows the user to select the Node and the Attribute to read. Press the button “Show Code” to display the corresponding code, and the button “Help” for further information.


On pressing the button “...” at “Read Request”, a window for browsing the address space opens. Expand the tree, select the desired Node and press “OK”.


The NodeId is now displayed in the field “Node Id” and you can select the attribute to read from the corresponding drop-down menu.


On pressing the button “Read”, the value of the node’s attribute is read and displayed in the corresponding field at “Read Response”. Press the button “...” to view details for the value. Check the box in front of “Use Asynchronous Pattern” to call “BeginRead” instead of “Read”.


See Read – Read With Index Range for an example for reading only a subset of an array variable.

Sample Code

The following code reads the selected Attribute for the selected Node from the server.

In this example the NodeId of the node to read is specified in a text field of the GUI. The NodeId is printed in the XML representation of a NodeId. So we can use the static method NodeId.Parse to get the NodeId.

The AttributeId can be selected in a drop-down box of the GUI. If you want to set the AttributeId directly in code, we recommend using the constants defined in UaBase.Attributes.

The only difference between this example and Read – Basic Read is that the NodeIds and AttributeIds can be set dynamically using the GUI and are not hard-coded.

// build a list of values to read.
List<ReadValueId> nodesToRead = new List<ReadValueId>();
// parse the node id and get the selected attribute id.
NodeId nodeId = NodeId.Parse(NodeIdTB.Text);
uint attributeId = ((DropDownItem)AttributeCB.SelectedItem).AttributeId;
// read the display name and the selected attribute for the node.
nodesToRead.Add(new ReadValueId() { NodeId = nodeId, AttributeId = Attributes.DisplayName });
nodesToRead.Add(new ReadValueId() { NodeId = nodeId, AttributeId = attributeId });
// this is a blocking call so show the wait cursor.
Cursor = Cursors.WaitCursor;
// read the value (setting a 10 second timeout).
List<DataValue> results = session.Read(
new RequestSettings() { OperationTimeout = 10000 });