locked
How to assign the value of my custom activity to the variable of the parent activity? RRS feed

  • Question

  • How to assign the value of my custom activity to the variable of the parent activity?

    Csutom activity code :

    public class ExecuteService : NativeActivity
    {
    /// <summary>
    /// 服务执行结果
    /// </summary>
    public OutArgument Result
    {
    get;
    set;
    }

    public ExecuteService()
    {
    }

    protected override void Execute(NativeActivityContext context)
    {

    this.Result.Set(context, "Ren");
    }
    }

    Monday, March 14, 2011 2:40 AM

All replies

  • I am not sure I understood you.

    To assign a return value, define a variable in the workflow at the scoop of the parent activity.

    In the WF environment, at the property pen just put the variable in the "Result" property

    After the Execute step of the code activity you will have the value in the variable you assigned to the "Result" property

    • Marked as answer by JL_Nostalgic Thursday, March 17, 2011 12:33 AM
    • Unmarked as answer by JL_Nostalgic Thursday, March 17, 2011 7:08 AM
    • Marked as answer by Andrew_Zhu Monday, March 21, 2011 2:35 AM
    • Unmarked as answer by JL_Nostalgic Thursday, April 7, 2011 6:36 AM
    Monday, March 14, 2011 4:48 PM
  • That is correct, you can pass values out of the Child activities through OutArguments, such as the built-in Result OutArgument of an Activity<T> or any outArguments that you specify. The parent activity would bind its variable to the desired outArgument, and when it finished executing the Parent's variable would have the value returned by the OutArgument.

    Steve Danielson [Microsoft]
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Use of included script samples are subject to the terms specified at http://www.microsoft.com/info/cpyright.htm

    • Marked as answer by JL_Nostalgic Thursday, March 17, 2011 12:33 AM
    • Unmarked as answer by JL_Nostalgic Thursday, March 17, 2011 7:08 AM
    • Marked as answer by JL_Nostalgic Thursday, March 17, 2011 7:08 AM
    • Unmarked as answer by JL_Nostalgic Thursday, March 17, 2011 7:08 AM
    • Marked as answer by Andrew_Zhu Monday, March 21, 2011 2:35 AM
    • Unmarked as answer by JL_Nostalgic Thursday, April 7, 2011 6:36 AM
    Tuesday, March 15, 2011 3:02 PM
  • I want to implement my workflow with code completely.

    Can you give me some example?

    Thanks a lot~

    Thursday, March 17, 2011 7:09 AM
  • The code :

    static Activity CreateActivity()
            {
                //定义参数
                var id = new InArgument<System.Int32>();
                var fullName = new OutArgument<System.String>();


                //定义变量
                var FirstName = new Variable<System.String>();
                var LastName = new Variable<System.String>();
                var FullName = new Variable<System.String>();

                //定义步骤变量
                ServiceInfo servieInfoExecuteServiceObject1 = new ServiceInfo();
              
                servieInfoExecuteServiceObject1.InParameters = new List<InParameter>();
                servieInfoExecuteServiceObject1.ServiceMethodInfo = methodExecuteServiceObject1;

                InParameter idInParameterExecuteServiceObject1 = new InParameter();
                idInParameterExecuteServiceObject1.Name = "id";
                idInParameterExecuteServiceObject1.Argument = System.Activities.Argument.Create(typeof(System.Int32), System.Activities.ArgumentDirection.In);
                idInParameterExecuteServiceObject1.Argument.Expression = ExpressionHelper.CreateExpression(typeof(System.Int32), "id", false);
                methodExecuteServiceObject1.InParameters.Add(idInParameterExecuteServiceObject1);


                OutParameter FirstNameOutParameterExecuteServiceObject1 = new OutParameter();
                FirstNameOutParameterExecuteServiceObject1.Name = "FirstName";
                FirstNameOutParameterExecuteServiceObject1.Type = typeof(System.String);
                methodExecuteServiceObject1.OutParameter = FirstNameOutParameterExecuteServiceObject1;
                servieInfoExecuteServiceObject1.ServiceMethodInfo = methodExecuteServiceObject1;
                ExecuteService ExecuteServiceObject1 = new ExecuteService()
                {
                    ServiceInfo = servieInfoExecuteServiceObject1,
                    //这里需要根据返回参数类型做不同的生成
                    Result = new System.Activities.OutArgument<System.String>(FirstName)
                };
                FlowStep FlowStepObject1 = new FlowStep() { Action = ExecuteServiceObject1 };


                ServiceInfo servieInfoExecuteServiceObject2 = new ServiceInfo();
                servieInfoExecuteServiceObject2.ServiceDN = "CN=Bussiness,CN=BussinessService,CN=Service,CN=X0,O=test,C=cn";
                servieInfoExecuteServiceObject2.EndPointAddress = "http://localhost/Bussiness/Test.svc";

                ServiceMethodInfo methodExecuteServiceObject2 = new ServiceMethodInfo();
                methodExecuteServiceObject2.MethodName = "GetLastName";
                methodExecuteServiceObject2.InParameters = new List<InParameter>();
                servieInfoExecuteServiceObject2.ServiceMethodInfo = methodExecuteServiceObject2;

                InParameter idInParameterExecuteServiceObject2 = new InParameter();
                idInParameterExecuteServiceObject2.Name = "id";
                idInParameterExecuteServiceObject2.Argument = System.Activities.Argument.Create(typeof(System.Int32), System.Activities.ArgumentDirection.In);
                idInParameterExecuteServiceObject2.Argument.Expression = ExpressionHelper.CreateExpression(typeof(System.Int32), "id", false);
                methodExecuteServiceObject2.InParameters.Add(idInParameterExecuteServiceObject2);


                OutParameter LastNameOutParameterExecuteServiceObject2 = new OutParameter();
                LastNameOutParameterExecuteServiceObject2.Name = "LastName";
                LastNameOutParameterExecuteServiceObject2.Type = typeof(System.String);
                methodExecuteServiceObject2.OutParameter = LastNameOutParameterExecuteServiceObject2;
                servieInfoExecuteServiceObject2.ServiceMethodInfo = methodExecuteServiceObject2;
                ExecuteService ExecuteServiceObject2 = new ExecuteService()
                {
                    ServiceInfo = servieInfoExecuteServiceObject2,
                    //这里需要根据返回参数类型做不同的生成
                    Result = new System.Activities.OutArgument<System.String>(LastName)
                };
                FlowStep FlowStepObject2 = new FlowStep() { Action = ExecuteServiceObject2 };


                ServiceInfo servieInfoExecuteServiceObject3 = new ServiceInfo();
                servieInfoExecuteServiceObject3.ServiceDN = "CN=Bussiness,CN=BussinessService,CN=Service,CN=X0,O=test,C=cn";
                servieInfoExecuteServiceObject3.EndPointAddress = "http://localhost/Bussiness/Test.svc";

                ServiceMethodInfo methodExecuteServiceObject3 = new ServiceMethodInfo();
                methodExecuteServiceObject3.MethodName = "GetFullName";
                methodExecuteServiceObject3.InParameters = new List<InParameter>();
                servieInfoExecuteServiceObject3.ServiceMethodInfo = methodExecuteServiceObject3;

                InParameter firstNameInParameterExecuteServiceObject3 = new InParameter();
                firstNameInParameterExecuteServiceObject3.Name = "firstName";
                firstNameInParameterExecuteServiceObject3.Argument = System.Activities.Argument.Create(typeof(System.String), System.Activities.ArgumentDirection.In);
                firstNameInParameterExecuteServiceObject3.Argument.Expression = ExpressionHelper.CreateExpression(typeof(System.String), "FirstName", false);
                methodExecuteServiceObject3.InParameters.Add(firstNameInParameterExecuteServiceObject3);

                InParameter lastNameInParameterExecuteServiceObject3 = new InParameter();
                lastNameInParameterExecuteServiceObject3.Name = "lastName";
                lastNameInParameterExecuteServiceObject3.Argument = System.Activities.Argument.Create(typeof(System.String), System.Activities.ArgumentDirection.In);
                lastNameInParameterExecuteServiceObject3.Argument.Expression = ExpressionHelper.CreateExpression(typeof(System.String), "LastName", false);
                methodExecuteServiceObject3.InParameters.Add(lastNameInParameterExecuteServiceObject3);


                OutParameter fullNameOutParameterExecuteServiceObject3 = new OutParameter();
                fullNameOutParameterExecuteServiceObject3.Name = "fullName";
                fullNameOutParameterExecuteServiceObject3.Type = typeof(System.String);
                methodExecuteServiceObject3.OutParameter = fullNameOutParameterExecuteServiceObject3;
                servieInfoExecuteServiceObject3.ServiceMethodInfo = methodExecuteServiceObject3;
                ExecuteService ExecuteServiceObject3 = new ExecuteService()
                {
                    ServiceInfo = servieInfoExecuteServiceObject3,
                    //这里需要根据返回参数类型做不同的生成
                    Result = System.Activities.OutArgument.CreateReference(fullName, "fullName")
                };
                FlowStep FlowStepObject3 = new FlowStep() { Action = ExecuteServiceObject3 };

                //步骤关联
                FlowStepObject1.Next = FlowStepObject2;
                FlowStepObject2.Next = FlowStepObject3;

                //定义流程活动
                Flowchart FlowChartObject1 = new Flowchart()
                {
                    Variables =
                    {
                        FirstName,
                        LastName,
                        FullName,
                    },

                    StartNode = FlowStepObject1,
                    Nodes =
                    {
               FlowStepObject1,
               FlowStepObject2,
               FlowStepObject3,
                    }
                };

                //生成根活动
                Activity activity = new DynamicActivity()
                {
                    Properties = {
                        new DynamicActivityProperty
            {
             Name = "id",
             Type = typeof(InArgument<System.Int32>),
             Value = id
            },
         new DynamicActivityProperty
            {
             Name = "fullName",
             Type = typeof(OutArgument<System.String>),
             Value = fullName
            },
                    },
                    Implementation = () => FlowChartObject1
                };
                return activity;
            }

    Thursday, March 17, 2011 7:14 AM
  • static Activity CreateActivity()
            {
                //Argument
                var id = new InArgument<System.Int32>();
                var fullName = new OutArgument<System.String>();

                //Variable
                var FirstName = new Variable<System.String>();
                var LastName = new Variable<System.String>();
                var FullName = new Variable<System.String>();

                //FlowStep
                ServiceInfo servieInfoExecuteServiceObject1 = new ServiceInfo();
                servieInfoExecuteServiceObject1.InParameters = new List<InParameter>();


                InParameter idInParameterExecuteServiceObject1 = new InParameter();
                idInParameterExecuteServiceObject1.Name = "id";
                idInParameterExecuteServiceObject1.Argument = System.Activities.Argument.Create(typeof(System.Int32), System.Activities.ArgumentDirection.In);
                idInParameterExecuteServiceObject1.Argument.Expression = ExpressionHelper.CreateExpression(typeof(System.Int32), "id", false);
                servieInfoExecuteServiceObject1.InParameters.Add(idInParameterExecuteServiceObject1);


                OutParameter FirstNameOutParameterExecuteServiceObject1 = new OutParameter();
                FirstNameOutParameterExecuteServiceObject1.Name = "FirstName";
                FirstNameOutParameterExecuteServiceObject1.Type = typeof(System.String);
                servieInfoExecuteServiceObject1.OutParameter = FirstNameOutParameterExecuteServiceObject1;
                ExecuteService ExecuteServiceObject1 = new ExecuteService()
                {
                    ServiceInfo = servieInfoExecuteServiceObject1,
                    Result = new System.Activities.OutArgument<System.String>(FirstName)
                };
                FlowStep FlowStepObject1 = new FlowStep() { Action = ExecuteServiceObject1 };


                ServiceInfo servieInfoExecuteServiceObject2 = new ServiceInfo();
                servieInfoExecuteServiceObject2.InParameters = new List<InParameter>();

                InParameter idInParameterExecuteServiceObject2 = new InParameter();
                idInParameterExecuteServiceObject2.Name = "id";
                idInParameterExecuteServiceObject2.Argument = System.Activities.Argument.Create(typeof(System.Int32), System.Activities.ArgumentDirection.In);
                idInParameterExecuteServiceObject2.Argument.Expression = ExpressionHelper.CreateExpression(typeof(System.Int32), "id", false);
                servieInfoExecuteServiceObject2.InParameters.Add(idInParameterExecuteServiceObject2);


                OutParameter LastNameOutParameterExecuteServiceObject2 = new OutParameter();
                LastNameOutParameterExecuteServiceObject2.Name = "LastName";
                LastNameOutParameterExecuteServiceObject2.Type = typeof(System.String);
                servieInfoExecuteServiceObject2.OutParameter = LastNameOutParameterExecuteServiceObject2;
                ExecuteService ExecuteServiceObject2 = new ExecuteService()
                {
                    ServiceInfo = servieInfoExecuteServiceObject2,
                    Result = new System.Activities.OutArgument<System.String>(LastName)
                };
                FlowStep FlowStepObject2 = new FlowStep() { Action = ExecuteServiceObject2 };


                ServiceInfo servieInfoExecuteServiceObject3 = new ServiceInfo();
                servieInfoExecuteServiceObject3.InParameters = new List<InParameter>();

                InParameter firstNameInParameterExecuteServiceObject3 = new InParameter();
                firstNameInParameterExecuteServiceObject3.Name = "firstName";
                firstNameInParameterExecuteServiceObject3.Argument = System.Activities.Argument.Create(typeof(System.String), System.Activities.ArgumentDirection.In);
                firstNameInParameterExecuteServiceObject3.Argument.Expression = ExpressionHelper.CreateExpression(typeof(System.String), "FirstName", false);
                servieInfoExecuteServiceObject3.InParameters.Add(firstNameInParameterExecuteServiceObject3);

                InParameter lastNameInParameterExecuteServiceObject3 = new InParameter();
                lastNameInParameterExecuteServiceObject3.Name = "lastName";
                lastNameInParameterExecuteServiceObject3.Argument = System.Activities.Argument.Create(typeof(System.String), System.Activities.ArgumentDirection.In);
                lastNameInParameterExecuteServiceObject3.Argument.Expression = ExpressionHelper.CreateExpression(typeof(System.String), "LastName", false);
                servieInfoExecuteServiceObject3.InParameters.Add(lastNameInParameterExecuteServiceObject3);


                OutParameter fullNameOutParameterExecuteServiceObject3 = new OutParameter();
                fullNameOutParameterExecuteServiceObject3.Name = "fullName";
                fullNameOutParameterExecuteServiceObject3.Type = typeof(System.String);
                servieInfoExecuteServiceObject3.OutParameter = fullNameOutParameterExecuteServiceObject3;
               
                ExecuteService ExecuteServiceObject3 = new ExecuteService()
                {
                    ServiceInfo = servieInfoExecuteServiceObject3,
                    Result = System.Activities.OutArgument.CreateReference(fullName, "fullName")
                };
                FlowStep FlowStepObject3 = new FlowStep() { Action = ExecuteServiceObject3 };

                //
                FlowStepObject1.Next = FlowStepObject2;
                FlowStepObject2.Next = FlowStepObject3;

                //FlowChart
                Flowchart FlowChartObject1 = new Flowchart()
                {
                    Variables =
                    {
                        FirstName,
                        LastName,
                        FullName,
                    },

                    StartNode = FlowStepObject1,
                    Nodes =
                    {
               FlowStepObject1,
               FlowStepObject2,
               FlowStepObject3,
                    }
                };

                //Root Activity
                Activity activity = new DynamicActivity()
                {
                    Properties = {
                        new DynamicActivityProperty
            {
             Name = "id",
             Type = typeof(InArgument<System.Int32>),
             Value = id
            },
         new DynamicActivityProperty
            {
             Name = "fullName",
             Type = typeof(OutArgument<System.String>),
             Value = fullName
            },
                    },
                    Implementation = () => FlowChartObject1
                };
                return activity;
            }

    Thursday, March 17, 2011 7:17 AM
  • Hi, JL_Nostalgic

    ->"I want to implement my workflow with code completely."
    Here is a blog entry could be helpful to you:
    http://xhinker.com/post/WF4Authoring-WF4-using-imperative-code(II).aspx

    Regards
    MSDN Community Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    This posting is provided "AS IS" with no warranties, and confers no rights. My Blog: http://xhinker.com
    Microsoft Windows Workflow Foundation 4.0 Cookbook
    Monday, March 21, 2011 2:35 AM
  • Hi, JL_Nostalgic

    ->"I want to implement my workflow with code completely."
    Here is a blog entry could be helpful to you:
    http://xhinker.com/post/WF4Authoring-WF4-using-imperative-code(II).aspx

    Regards
    MSDN Community Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    This posting is provided "AS IS" with no warranties, and confers no rights. My Blog: http://xhinker.com
    Microsoft Windows Workflow Foundation 4.0 Cookbook
    How to assign the value of my custom activity to the variable of the parent activity?
    Thursday, March 31, 2011 2:52 AM