Avoidance "An activity can only get the location of the arguments it owns."

This is the next question: Setting internal properties in composite WF4 actions at design time .

I am creating a compound Windows workflow activity (in .NET 4) that contains Get and Submit operations with some predefined properties. This is a NativeActivity, not an Activity Template. (See @Maurice's answer to the above question for an example.)

If I try to set the InArgument parameter associated with the internal SendReply from Execute (using the parent context), I get an InvalidOperationException:

Activity can only get the location of the arguments it owns. Events "CreateInstance" tries to get the location of the argument 'Parameter0' which belongs to the activity 'SendReply'.

In my case, I am trying to set a CorrelationHandle, but I believe that this will affect the SendParametersContent parameters as well. How can I get around this?

+3
source share
1 answer

CacheMetadata, CorrelationHandle. , Variable AddImplementationVariable, AddImplementationChild.

protected override void CacheMetadata(NativeActivityMetadata metadata)
{
    _receive = _receive ?? new Receive();
    _sendReply = _sendReply ?? new SendReply();
    _receive.CanCreateInstance = true;
    metadata.AddImplementationChild(_receive);
    metadata.AddImplementationChild(_sendReply);

    _receive.ServiceContractName = ServiceContractName;
    _receive.OperationName = OperationName;

    var correlationHandle = new Variable<CorrelationHandle>("correlationHandle");
    metadata.AddImplementationVariable(correlationHandle);
    var correlationInitializer = new RequestReplyCorrelationInitializer()
    {
        CorrelationHandle = new InArgument<CorrelationHandle>(correlationHandle)
    };
    _receive.CorrelationInitializers.Add(correlationInitializer);


    var firstName = new Variable<string>("firstName");
    metadata.AddImplementationVariable(firstName);
    var args = new ReceiveParametersContent();
    args.Parameters["firstName"] = new OutArgument<string>(firstName);
    _receive.Content = args;


    _sendReply.Request = _receive;
    var results = new SendParametersContent();
    results.Parameters["greeting"] = new InArgument<string>(new VisualBasicValue<string>("\"Hello \" & firstName"));
    _sendReply.Content = results;

    base.CacheMetadata(metadata);
}
+4

Source: https://habr.com/ru/post/1778190/


All Articles