Creating DataTypes

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

Moderator: uasdknet

Post Reply
WarGuruMM
Jr. Member
Jr. Member
Posts: 3
Joined: 27 Mar 2015, 14:17

Creating DataTypes

Post by WarGuruMM »

Hi,

I'm trying to add Object Type Nodes and organize them for my project (set variables, method and other properties) but the server is giving me BadUserAccessDenied.
Adding nodes and variables to the Demo Server Object is working.
I have overriden the:

Code: Select all

 protected override bool HasAccessToAddNode(RequestContext context, BrowseHandle parent, NodeId referenceTypeId, NodeId typeDefinitionId)
{
        return true;
}
So now what I want to do is add Nodes which are with NodeClass ObjectType like this:

Code: Select all

 
                NodeId parendNode = NodeId.Parse(request.ParentIdentifier);
                NodeId referenceType = NodeId.Parse(request.ReferenceTypeIdentifier);
                ExpandedNodeId nodeType = ExpandedNodeId.Parse(request.NodeTypeIdentifier);
                AddNodesItem nodeToAdd = new AddNodesItem()
                {
                    ParentNodeId = parendNode, // this is Object Type folder, or Base Object Type
                    RequestedNewNodeId = new NodeId(request.Name, parendNode.NamespaceIndex), // with a given name under the parentNode namespaceindex
                    ReferenceTypeId = referenceType, // reference type I'm setting to HierarchicalReferences
                    NodeClass = (NodeClass)request.NodeClass, // Node class is ObjectType
                    TypeDefinition = nodeType, // Unspecified
                    BrowseName = new QualifiedName(request.Name, 1) 
                };
                switch (nodeToAdd.NodeClass)
                {
                    case NodeClass.Object:
                    {
                        nodeToAdd.NodeAttributes = new ExtensionObject(new ObjectAttributes()
                        {
                            SpecifiedAttributes = (uint)(NodeAttributesMask.DisplayName),
                            DisplayName = request.DisplayName
                        });
                        break;
                    }
                    case NodeClass.Variable:
                    {
                        NodeId DataType = NodeId.Parse(request.DataTypeIdentifier);
                        TypeInfo info = new TypeInfo(DataType, null);
                        nodeToAdd.NodeAttributes = new ExtensionObject(new VariableAttributes()
                        {
                            SpecifiedAttributes = (uint)(NodeAttributesMask.DataType | NodeAttributesMask.ValueRank | NodeAttributesMask.DisplayName),
                            DisplayName = request.DisplayName,
                            DataType = DataType,
                            ValueRank = request.ValueRank,
                            AccessLevel =  AccessLevels.CurrentReadOrWrite
                        });
                        break;
                    }
                }
Do I need to be logged in with some user, or maybe I should override some other access rights?
Also I can maybe try to do this on the server implementation and create my own model, but I would like to make an API as this is my goal and to allow for users to manage these through a client web app.

Regards,
Agon

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

Re: Creating DataTypes

Post by Support Team »

Hi Agon,

In your case you need to to connected as special user. Your HasAccessToAddNode method return true without checking the UserIdentity of the RequestContext.

Returning true in HasAccessToAddNode allows adding nodes to your NodeManager. If the client trys to add a node to another NodeManager, the HasAccessToAddNode of your NodeManager method is not called. Please make sure that the client uses the correct NamespaceIndex in the RequestedNewNode of nodeToAdd.

Best Regards
Support Team

WarGuruMM
Jr. Member
Jr. Member
Posts: 3
Joined: 27 Mar 2015, 14:17

Re: Creating DataTypes

Post by WarGuruMM »

In the DemoServer, what kind of user can add Object Types. Do I need to specify a model in the server for that or can I do it via session.AddNodes?
Or, maybe I can override the hasAccessToAddNode to the ObjectType's NodeManager...

WarGuruMM
Jr. Member
Jr. Member
Posts: 3
Joined: 27 Mar 2015, 14:17

Re: Creating DataTypes

Post by WarGuruMM »

I resolved the issue, I was trying to do something that was un-intended, that is messing with the object types node. After creating a node under object types on the server side now I can manipulate it to create my own object types. Now everything is clear

Post Reply