StatusCode "BadTypeDefinitionInvalid" after AddNodes call

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

Moderator: uasdknet

Post Reply
goturvijay
Jr. Member
Jr. Member
Posts: 3
Joined: 07 Jun 2014, 01:26

StatusCode "BadTypeDefinitionInvalid" after AddNodes call

Post by goturvijay »

Hello

I am trying to implement a client with which I can add/modify nodes on a UA server..
I am using the UA .NET SDK

I start with, I am trying to add a new variable Node to an object in an existing data model on a running UA server..
I call the AddNodes function with the following AddNodesItem:

AddNodesItem NewNode = new AddNodesItem()
{
ParentNodeId = parentNodeId,
ReferenceTypeId = UnifiedAutomation.UaBase.ReferenceTypeIds.HasComponent,
TypeDefinition = UnifiedAutomation.UaBase.VariableTypeIds.AnalogItemType,
BrowseName = "Test Var",
NodeClass = UnifiedAutomation.UaBase.NodeClass.Variable
};

The AddNodes function returns a result with a StatusCode "BadTypeDefinitionInvalid"..

I tried changing the TypeDefinition property to other values like DataItemType or BaseDataVariableType, with no change in the result..
Note: parentNodeId is previously assigned to the NodeID of an object in the server datamodel. It is of type BaseObjectType and already references a few variable nodes.

Am I missing any crucial step before I can add Nodes to the server..??

Regards
Vijay

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

Re: StatusCode "BadTypeDefinitionInvalid" after AddNodes cal

Post by Support Team »

Hello,

You need to specify the VariableAttributes within the AddNodesItem.

Here is some sample code to add a node to the DemoServer.

Code: Select all

ushort namespaceIndex = (ushort) m_Session.NamespaceUris.IndexOf("http://www.unifiedautomation.com/DemoServer/");
VariableAttributes variableAttributes = new VariableAttributes()
{
    AccessLevel = AccessLevels.CurrentReadOrWrite,
    DataType = DataTypeIds.Double,
    Historizing = false,
    SpecifiedAttributes = Attributes.AccessLevel|Attributes.DataType|Attributes.Historizing
};
AddNodesItem addNodesItem = new AddNodesItem()
{
    NodeClass = NodeClass.Variable,
    ReferenceTypeId = ReferenceTypeIds.Organizes,
    RequestedNewNodeId = new NodeId("TestVar", namespaceIndex),
    TypeDefinition = VariableTypeIds.AnalogItemType,
    BrowseName = new QualifiedName("TestVar", namespaceIndex),
    ParentNodeId = new ExpandedNodeId("Demo", namespaceIndex),
    NodeAttributes = new ExtensionObject(variableAttributes)
};
IList<AddNodesItem> nodesToAdd = new List<AddNodesItem>();
nodesToAdd.Add(addNodesItem);
List<AddNodesResult> results = m_Session.AddNodes(nodesToAdd, null);
NOTE: You have to override

Code: Select all

protected override bool HasAccessToAddNode(
    RequestContext context,
    BrowseHandle parent,
    NodeId referenceTypeId,
    NodeId typeDefinitionId)
in your NodeManager to allow clients to add nodes with the AddNodes service.

Best regards
Support Team

Post Reply