create method node in code

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

Moderator: uasdknet

Post Reply
jxu2016
Jr. Member
Jr. Member
Posts: 4
Joined: 04 Nov 2015, 23:12

create method node in code

Post by jxu2016 »

hello:

Can you give an example of creating method node with input and output argument grammatically in C# code? I have a need to dynamically create the method nodes.

Thanks.

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

Re: create method node in code

Post by Support Team »

Hello,

The following method adds a UA Method node with InpurtArguments and OutputArguments properties to the Method folder in .NET DemoServer:

Code: Select all

private void CreateMethodInCode()
{
    CreateMethodSettings settings = new CreateMethodSettings()
    {
        ParentNodeId = new NodeId(Demo.Model.Objects.Demo_Method, DefaultNamespaceIndex),
        ReferenceTypeId = ReferenceTypeIds.HasComponent,
        RequestedNodeId = new NodeId("MethodInCode", DefaultNamespaceIndex),
        BrowseName = new QualifiedName("MethodInCode", DefaultNamespaceIndex),
        Executable = true,
        InputArguments = new List<Argument>(),
        OutputArguments = new List<Argument>()
    };

    settings.InputArguments.Add(new Argument()
    {
        DataType = DataTypeIds.Double,
        Name = "InputArgument1",
        Description = "The first input argument",
        ValueRank = ValueRanks.Scalar,
    });
    settings.InputArguments.Add(new Argument()
    {
        DataType = DataTypeIds.Double,
        Name = "InputArgument2",
        Description = "The second input argument",
        ValueRank = ValueRanks.Scalar,
    });

    settings.OutputArguments.Add(new Argument()
    {
        DataType = DataTypeIds.Double,
        Name = "Result",
        Description = "The output argument",
        ValueRank = ValueRanks.Scalar,
    });
    CreateMethod(Server.DefaultRequestContext, settings);
}
Best regards
Support Team

Post Reply