Reputation: 1709
I'm fairly new to OPCUA and could use an example on how to implement the AddNodes service in C# using the official .NET Standard SDK. Basically what I want to do is implementing my custom server and be able to call the AddNodes service from the client to add some nodes to a folder (and set their initial values).
I have seen there are various classes to inherit from, so I thought it would be the best to inherit from StandardServer and override the AddNodes method. After that, I could create my own custom node manager and call it from within this method. However, none of the sample node managers implement an AddNodes method (even the INodeManager interface doesn't) so I'm wondering if I am on the right track.
Has somebody already implemented the AddNodes service using this SDK and is willing to give me some hints how to do so? Did you just create your own AddNodes method on your custom node manager and add the nodes there? Some code snippets would be very helpful. Thank you!
Upvotes: 1
Views: 1063
Reputation: 2062
I think you are on the right track. SessionServerBase
is auto generated by Opc.Ua.Services.wsdl
. StandardServer
inherits from SessionServerBase
with only overriding subset of virtual methods.
So you need to override AddNodes
in StandardServer
, and below is an example to add nodes.
public override ResponseHeader AddNodes(
RequestHeader requestHeader,
AddNodesItemCollection nodesToAdd,
out AddNodesResultCollection results,
out DiagnosticInfoCollection diagnosticInfos)
{
results = null;
diagnosticInfos = null;
ValidateRequest(requestHeader);
foreach (var item in nodesToAdd)
{
if (item.NodeClass == NodeClass.Variable)
{
var node = new VariableNode
{
// TODO: Initialization
};
m_serverInternal.CoreNodeManager.AttachNode(node);
}
else if (item.NodeClass == NodeClass.VariableType)
{
var node = new VariableTypeNode
{
// TODO: Initialization
};
m_serverInternal.CoreNodeManager.AttachNode(node);
}
else
{
// TODO
}
}
return CreateResponse(requestHeader, StatusCodes.Good);
}
Upvotes: 3