How to return variant with custom object in a method call?

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

Moderator: uasdknet

Post Reply
opcstudent
Full Member
Full Member
Posts: 6
Joined: 16 Dec 2015, 15:41

How to return variant with custom object in a method call?

Post by opcstudent »

Hi,

i would like to return custom objects during a method call.

For example, given a class Test with two properties, how to return a variant with a custom object inside.

Test t = new Test { N = 1, S = "asdf" };
Variant v = new Variant(t1, TypeInfo.Construct(t1));

Although the variant object has its Value property correctly filled on the server side, the client receives a null object.

Is this is related to TypeInfo, right?
How to get around this problem?

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

Re: How to return variant with custom object in a method cal

Post by Support Team »

We assume that the struture you want to return in the method call is know at compile time. We recommend to use UaModeler for modelling the structure und use the generated code in your server-application. Alternatively you can write the same code by hand. Please see the VectorAdd example in DemoServer application. This example shows how to use structures as input arguments and return structures as output arguments for method call.

You can test your code using UaExpert which supports Method calls taking structures as arguments.
Best regards
Unified Automation Support Team

Post Reply