OPCFoundation / UA-.NET-Legacy

OPC Foundation Unified Architecture .NET Reference Implementations
330 stars 298 forks source link

How To Call Method #194

Closed lekhoi99 closed 3 years ago

lekhoi99 commented 3 years ago

I want to Call Method from OPC UA Server. I followed the instructions but It doesn't work . This is my code :

        /// [Step 1]
        // parse the object id.
        NodeId objectId = NodeId.Parse("ns=2;i=15108");

        // get the selected method id.            
        NodeId methodId = NodeId.Parse("ns=2;i=15057");

        List<ExtensionObject> ar = new List<ExtensionObject>();

        // get input arguments.
        UInt32 a = 1;
        List<Variant> inputArguments = new List<Variant>
            {
                new Variant(string.Empty, TypeInfo.Scalars.String), new Variant(a,TypeInfo.Scalars.UInt32), new Variant(string.Empty, TypeInfo.Scalars.String),
                new Variant(ar.ToArray(), TypeInfo.Arrays.ExtensionObject), new Variant(string.Empty, TypeInfo.Scalars.String)
            };

        /// [Step 2]
        List<StatusCode> inputArgumentErrors;
        List<Variant> outputArguments = null;

        // call the method on the server.
        StatusCode error = _Session.Call(objectId,methodId,inputArguments,out inputArgumentErrors,out outputArguments);

It 's my Error from _Session.Call :

CS1615 Argument 4 may not be passed with the 'out' keyword CS1615 Argument 5 may not be passed with the 'out' keyword

How can I fix it ?

SoftwareDave commented 3 years ago

Method calls are really hard... There appear to be two (override) versions of the Session.Call method. I examined my application code; unfortunately we are using the "other" virtual Session.Call (which is also very complicated to set up).

ResponseHeader Session.Call( RequestHeader requestHeader, CallMethodRequestCollection methodsToCall, out CallMethodResultCollection results, out DiagnosticInfoCollection diagnosticInfos);

On Mon, May 24, 2021 at 9:20 AM lekhoi99 @.***> wrote:

I want to Call Method from OPC UA Server. I followed the instructions but It doesn't work . This is my code :

    /// [Step 1]
    // parse the object id.
    NodeId objectId = NodeId.Parse("ns=2;i=15108");

    // get the selected method id.
    NodeId methodId = NodeId.Parse("ns=2;i=15057");

    List<ExtensionObject> ar = new List<ExtensionObject>();

    // get input arguments.
    UInt32 a = 1;
    List<Variant> inputArguments = new List<Variant>
        {
            new Variant(string.Empty, TypeInfo.Scalars.String), new Variant(a,TypeInfo.Scalars.UInt32), new Variant(string.Empty, TypeInfo.Scalars.String),
            new Variant(ar.ToArray(), TypeInfo.Arrays.ExtensionObject), new Variant(string.Empty, TypeInfo.Scalars.String)
        };

    /// [Step 2]
    List<StatusCode> inputArgumentErrors;
    List<Variant> outputArguments = null;

    // call the method on the server.
    StatusCode error = _Session.Call(objectId,methodId,inputArguments,out inputArgumentErrors,out outputArguments);

It 's my Error from _Session.Call :

CS1615 Argument 4 may not be passed with the 'out' keyword CS1615 Argument 5 may not be passed with the 'out' keyword

How can I fix it ?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/OPCFoundation/UA-.NET-Legacy/issues/194, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAGQGJ5LBFMGLQISFCID6HLTPJ4DNANCNFSM45NQWU2Q .