开发者

How to get OutArgument from a scheduled activity inside a native activity?

开发者 https://www.devze.com 2023-02-14 12:06 出处:网络
I have an activity that consists of an Receive activity and a SendReply activity. The receive activity waits for a message then it writes it out to the console and then sends a reply.

I have an activity that consists of an Receive activity and a SendReply activity. The receive activity waits for a message then it writes it out to the console and then sends a reply.

The problem is I can't get the message from the Receive activity when it finishes.

Belowe is my activity class and the exception info.

public sealed class MyActivity : NativeActivity
{
    private Receive Receive { get; set; }
    private SendReply SendReply { get; set; }

    private Variable<CorrelationHandle> CorrelationHandle { get; set; }
    private Variable<string> MessageParameter { get; set; }
    private Variable<string> ResponseParameter { get; set; }

    public MyActivity()
    {   
        CorrelationHandle = new Variable<CorrelationHandle>("SenseProcessCorrelationHandle");
        MessageParameter = new Variable<string>("MessageParamter");
        ResponseParameter = new Variable<string>("ResponseParam");

        Receive = new Receive
        {
            ServiceContractName = XName.Get("{http://tempuri.org/}MyService" ),
            OperationName = "Trigger",
            Content = new ReceiveParametersContent
            {
                Parameters =
                {
                    { "Message", new OutArgument<string>(MessageParameter) },
                },
            },
            CanCreateInstance =开发者_如何学Python true, 
            CorrelationInitializers =
            {
                new RequestReplyCorrelationInitializer
                {
                    CorrelationHandle = new InArgument<CorrelationHandle>(CorrelationHandle),
                }
            }
        };

        SendReply = new SendReply
        {
            Request = Receive,
            Content = new SendMessageContent
            {
                Message = new InArgument<string>(ResponseParameter),
            }
        };

    }

    protected override void Execute(NativeActivityContext context)
    {
        context.ScheduleActivity(Receive, OnReceiveCompleted);
    }

    void OnReceiveCompleted(NativeActivityContext context, ActivityInstance inst)
    {

        /* Next code line throws exception
         * 
         * Activity '2: MyActivity' cannot access this variable because it is 
         * declared at the scope of activity '2: MyActivity'.  An activity 
         * can only access its own implementation variables.
         */
        Console.WriteLine(MessageParameter.Get(context));             

        context.ScheduleActivity(SendReply);
    }

    protected override void CacheMetadata(NativeActivityMetadata metadata)
    {
        metadata.AddChild(Receive);
        metadata.AddChild(SendReply);
        metadata.AddVariable(CorrelationHandle);
        metadata.AddVariable(ResponseParameter);
        metadata.AddVariable(MessageParameter);            
    }
}

If anyone knows what I'm doing wrong, I would appreciate any help.

Thanks


You must enter this code instead of your code:

CorrelationInitializers = 
{                 
    new RequestReplyCorrelationInitializer  
    {
        CorrelationHandle = CorrelationHandle 
    }          
}

Which second CorrelationHandle is your variable not make a new inargument.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号