OPC Studio User's Guide and Reference
CallMethod(IEasyUAClient,UACallArguments) Method
Example 



OpcLabs.EasyOpcUA Assembly > OpcLabs.EasyOpc.UA Namespace > IEasyUAClientExtension Class > CallMethod Method : CallMethod(IEasyUAClient,UACallArguments) Method
The client object that will perform the operation.

This is typically the EasyUAClient object.

The value of this parameter cannot be null (Nothing in Visual Basic).

Specifies which method to call in an OPC-UA server, and its input arguments.

The value of this parameter cannot be null (Nothing in Visual Basic).

Calls a specified OPC UA method, using an object that holds all necessary arguments.
Syntax
'Declaration
 
<ExtensionAttribute()>
<NotNullAttribute()>
Public Overloads Shared Function CallMethod( _
   ByVal client As IEasyUAClient, _
   ByVal callArguments As UACallArguments _
) As Object()
'Usage
 
Dim client As IEasyUAClient
Dim callArguments As UACallArguments
Dim value() As Object
 
value = IEasyUAClientExtension.CallMethod(client, callArguments)
[Extension()]
[NotNull()]
public static object[] CallMethod( 
   IEasyUAClient client,
   UACallArguments callArguments
)
[Extension()]
[NotNull()]
public:
static array<Object^>^ CallMethod( 
   IEasyUAClient^ client,
   UACallArguments^ callArguments
) 

Parameters

client
The client object that will perform the operation.

This is typically the EasyUAClient object.

The value of this parameter cannot be null (Nothing in Visual Basic).

callArguments
Specifies which method to call in an OPC-UA server, and its input arguments.

The value of this parameter cannot be null (Nothing in Visual Basic).

Return Value

Array of output arguments from the method call. The number of arguments and their types are given by the method.

This method never returns null (Nothing in Visual Basic).

The individual elements of the returned value can be null (Nothing in Visual Basic).

Exceptions
ExceptionDescription

A null reference (Nothing in Visual Basic) is passed to a method that does not accept it as a valid argument.

This is a usage error, i.e. it will never occur (the exception will not be thrown) in a correctly written program. Your code should not catch this exception.

The OPC UA operation has failed. This operation exception in uniformly used to allow common handling of various kinds of errors. The System.Exception.InnerException always contains information about the actual error cause.

This is an operation error that depends on factors external to your program, and thus cannot be always avoided. Your code must handle it appropriately.

Remarks

This method calls (invokes) a method (or methods) in an OPC server. Input and output arguments can be passed to/from methods.

If you want to call methods that are defined in the OPC UA specifications or OPC UA companion specifications, consider first whether extension methods or specialized client objects exist for the purpose, because using them is much easier. For example, in order to call methods provided by OPC UA Global Discovery Server (GDS), you should rather use the OpcLabs.EasyOpc.UA.Gds.EasyUAGlobalDiscoveryClientCore or the OpcLabs.EasyOpc.UA.Gds.EasyUACertificateManagementClientCore object, or use the methods provided by the OpcLabs.EasyOpc.UA.Application.IEasyUAClientServerApplication service.

This is an extension method (info: C#, VB.NET). In languages that have support for extensions methods (such as C# and VB.NET), you can use the extension method as if it were a regular method on the object that is its first parameter. In other languages (such as with Python.NET), you will call the extension as a static method, and pass it the object on which it acts as its first parameter.

Example
// This example shows how to call a single method, and pass arguments to and from it.
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
// OPC client and subscriber examples in C# on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-CSharp .
// Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
// a commercial license in order to use Online Forums, and we reply to every post.

using System;
using OpcLabs.EasyOpc.UA;
using OpcLabs.EasyOpc.UA.OperationModel;

namespace UADocExamples._EasyUAClient
{
    class CallMethod
    {
        public static void Main1()
        {
            UAEndpointDescriptor endpointDescriptor =
                "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer";
            // or "http://opcua.demo-this.com:51211/UA/SampleServer" (currently not supported)
            // or "https://opcua.demo-this.com:51212/UA/SampleServer/"

            object[] inputs =
            {
                false, 
                1, 
                2, 
                3, 
                4, 
                5, 
                6, 
                7, 
                8, 
                9, 
                10
            };

            TypeCode[] typeCodes =
            {
                TypeCode.Boolean,
                TypeCode.SByte,
                TypeCode.Byte,
                TypeCode.Int16,
                TypeCode.UInt16,
                TypeCode.Int32,
                TypeCode.UInt32,
                TypeCode.Int64,
                TypeCode.UInt64,
                TypeCode.Single,
                TypeCode.Double
            };

            // Instantiate the client object
            var client = new EasyUAClient();

            // Perform the operation.
            object[] outputs;
            try
            {
                outputs = client.CallMethod(
                    endpointDescriptor,
                    "nsu=http://test.org/UA/Data/ ;i=10755",
                    "nsu=http://test.org/UA/Data/ ;i=10756",
                    inputs,
                    typeCodes);
            }
            catch (UAException uaException)
            {
                Console.WriteLine($"*** Failure: {uaException.GetBaseException().Message}");
                return;
            }

            // Display results
            for (int i = 0; i < outputs.Length; i++)
                Console.WriteLine($"outputs[{i}]: {outputs[i]}");

            // Example output:
            //outputs[0]: False
            //outputs[1]: 1
            //outputs[2]: 2
            //outputs[3]: 3
            //outputs[4]: 4
            //outputs[5]: 5
            //outputs[6]: 6
            //outputs[7]: 7
            //outputs[8]: 8
            //outputs[9]: 9
            //outputs[10]: 10        
        }
    }
}
# This example shows how to call a single method, and pass arguments to and from it.
#
# Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
# OPC client and subscriber examples in PowerShell on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-PowerShell .
# Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
# a commercial license in order to use Online Forums, and we reply to every post.

#requires -Version 5.1
using namespace System
using namespace OpcLabs.EasyOpc.UA
using namespace OpcLabs.EasyOpc.UA.OperationModel

# The path below assumes that the current directory is [ProductDir]/Examples-NET/PowerShell/Windows .
Add-Type -Path "../../../Components/Opclabs.QuickOpc/net472/OpcLabs.EasyOpcUA.dll"
Add-Type -Path "../../../Components/Opclabs.QuickOpc/net472/OpcLabs.EasyOpcUAComponents.dll"

[UAEndpointDescriptor]$endpointDescriptor =
    "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer"
# or "http://opcua.demo-this.com:51211/UA/SampleServer" (currently not supported)
# or "https://opcua.demo-this.com:51212/UA/SampleServer/"

$inputs = @(
    $false,
    1, 
    2, 
    3, 
    4, 
    5, 
    6, 
    7, 
    8, 
    9, 
    10)

$typeCodes = @(
    [TypeCode]::Boolean,
    [TypeCode]::SByte,
    [TypeCode]::Byte,
    [TypeCode]::Int16,
    [TypeCode]::UInt16,
    [TypeCode]::Int32,
    [TypeCode]::UInt32,
    [TypeCode]::Int64,
    [TypeCode]::UInt64,
    [TypeCode]::Single,
    [TypeCode]::Double)

# Instantiate the client object.
$client = New-Object EasyUAClient

# Perform the operation.
try {
    $outputs = $client.CallMethod(
                    $endpointDescriptor,
                    "nsu=http://test.org/UA/Data/ ;i=10755",
                    "nsu=http://test.org/UA/Data/ ;i=10756",
                    $inputs,
                    $typeCodes)
}
catch [UAException] {
    Write-Host "*** Failure: $($PSItem.Exception.GetBaseException().Message)"
    return
}

# Display results
for ($i = 0; $i -lt $outputs.Length; $i++) {
    Write-Host "outputs[$($i)]: $($outputs[$i])"
}


# Example output:
#
#outputs[0]: False
#outputs[1]: 1
#outputs[2]: 2
#outputs[3]: 3
#outputs[4]: 4
#outputs[5]: 5
#outputs[6]: 6
#outputs[7]: 7
#outputs[8]: 8
#outputs[9]: 9
#outputs[10]: 10        
' This example shows how to call a single method, and pass arguments to and from it.
'
' Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
' OPC client and subscriber examples in VB.NET on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-VBNET .
' Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
' a commercial license in order to use Online Forums, and we reply to every post.

Imports OpcLabs.EasyOpc.UA
Imports OpcLabs.EasyOpc.UA.OperationModel

Namespace _EasyUAClient
    Friend Class CallMethod
        Public Shared Sub Main1()

            Dim endpointDescriptor As UAEndpointDescriptor =
                "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer"
            ' or "http://opcua.demo-this.com:51211/UA/SampleServer" (currently not supported)
            ' or "https://opcua.demo-this.com:51212/UA/SampleServer/"

            Dim inputs() As Object =
            { _
                False,
                1,
                2,
                3,
                4,
                5,
                6,
                7,
                8,
                9,
                10
            }

            Dim typeCodes() As TypeCode =
            { _
                TypeCode.Boolean,
                TypeCode.SByte,
                TypeCode.Byte,
                TypeCode.Int16,
                TypeCode.UInt16,
                TypeCode.Int32,
                TypeCode.UInt32,
                TypeCode.Int64,
                TypeCode.UInt64,
                TypeCode.Single,
                TypeCode.Double
            }

            ' Instantiate the client object
            Dim client = New EasyUAClient()

            ' Perform the operation
            Dim outputs() As Object
            Try
                outputs = client.CallMethod( _
                    endpointDescriptor, _
                    "nsu=http://test.org/UA/Data/ ;i=10755", _
                    "nsu=http://test.org/UA/Data/ ;i=10756", _
                    inputs, _
                    typeCodes)
            Catch uaException As UAException
                Console.WriteLine("*** Failure: {0}", uaException.GetBaseException.Message)
                Exit Sub
            End Try

            ' Display results
            For i As Integer = 0 To outputs.Length - 1
                Console.WriteLine("outputs[{0}]: {1}", i, outputs(i))
            Next i

            ' Example output:
            'outputs[0]: False
            'outputs[1]: 1
            'outputs[2]: 2
            'outputs[3]: 3
            'outputs[4]: 4
            'outputs[5]: 5
            'outputs[6]: 6
            'outputs[7]: 7
            'outputs[8]: 8
            'outputs[9]: 9
            'outputs[10]: 10        
        End Sub
    End Class
End Namespace
# This example shows how to call a single method, and pass arguments to and from it.
#
# Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
# OPC client and subscriber examples in Python on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-Python .
# Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
# a commercial license in order to use Online Forums, and we reply to every post.
# The QuickOPC package is needed. Install it using "pip install opclabs_quickopc".
import opclabs_quickopc

# Import .NET namespaces.
from System import *
from OpcLabs.EasyOpc.UA import *
from OpcLabs.EasyOpc.UA.OperationModel import *


endpointDescriptor = UAEndpointDescriptor('opc.tcp://opcua.demo-this.com:51210/UA/SampleServer')
# or 'http://opcua.demo-this.com:51211/UA/SampleServer' (currently not supported)
# or 'https://opcua.demo-this.com:51212/UA/SampleServer/'

# 
inputs = [False, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
typeCodes = [
    TypeCode.Boolean,
    TypeCode.SByte,
    TypeCode.Byte,
    TypeCode.Int16,
    TypeCode.UInt16,
    TypeCode.Int32,
    TypeCode.UInt32,
    TypeCode.Int64,
    TypeCode.UInt64,
    TypeCode.Single,
    TypeCode.Double,
    ]

# Instantiate the client object.
client = EasyUAClient()

# Perform the operation.
try:
    outputs = IEasyUAClientExtension.CallMethod(client,
        endpointDescriptor,
        UANodeDescriptor('nsu=http://test.org/UA/Data/ ;i=10755'),
        UANodeDescriptor('nsu=http://test.org/UA/Data/ ;i=10756'),
        inputs,
        typeCodes)
except UAException as uaException:
    print('*** Failure: ' + uaException.GetBaseException().Message)
    exit()

# Display results.
for i, value in enumerate(outputs):
     print('outputs[', i, ']: ', value, sep='')


# Example output:
#outputs[0]: False
#outputs[1]: 1
#outputs[2]: 2
#outputs[3]: 3
#outputs[4]: 4
#outputs[5]: 5
#outputs[6]: 6
#outputs[7]: 7
#outputs[8]: 8
#outputs[9]: 9.0
#outputs[10]: 10.0
Requirements

Target Platforms: .NET Framework: Windows 10 (selected versions), Windows 11 (selected versions), Windows Server 2016, Windows Server 2022; .NET: Linux, macOS, Microsoft Windows

See Also