开发者

Correlate a graphical recieve with another one inside a code activity

you could imagine an xaml service that exposes a receive activity. This is the first activity in my worklow. Behind this receive there are simple activities as InitializateCorrelation", "ass开发者_StackOverflow社区ign", "delay"... whatever. Then I have a custom activity that was made with the activity designer. So I really have a code activity in my main workflow. This offers a drag and drop zone to allow to a developer customize the activity. But I want that this activity has a fixed receive activity at first. This receive must correlate using the first one correlation handle that was initialized using information got in the first receive of the service.

My problem is than I can not correlate the receive in the code activity using the correlation handle initialized in the xaml. Im getting time out errors when I invoke the second receive (code receive).

Do you know what is wrong?

This is the code of my code activity

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Activities;
using System.ComponentModel;
using WF4ActivityDesignerLibrary.ActivityDesigner;
using System.Xml.Linq;
using System.ServiceModel.Activities;
using System.ServiceModel;
using System.Activities.Statements;

namespace WF4ActivityDesignerLibrary.Activities
{
    [Designer(typeof(ContainerWithMultipleActivitiesDesigner))]
    public class ActivityWithMultipleChild : NativeActivity
    {

        public List<Activity> Activities { get; set; }
        private Receive ReceiveCancel { get; set; }
        private SendReply ReplyCancel { get; set; }
        private CorrelationScope Scope { get; set; }
        public InArgument<System.ServiceModel.Activities.CorrelationHandle> HandleToCorrelate { get; set; }
        private Variable<CorrelationHandle> CorrelationHandle { get; set; }
        private Variable<string> orderid = new Variable<string> { Name = "orderid" };



        //public SendReply SendReplyCancel { get; set; }

        public ActivityWithMultipleChild()
        {
            Activities = new List<Activity>();
            InitializeReceiveAndReply();
        }

        private void InitializeReceiveAndReply()
        {
            CorrelationHandle = new Variable<CorrelationHandle>("SenseProcessCorrelationHandle");



            ReceiveCancel = new Receive
            {
                CanCreateInstance = false,
                ServiceContractName = "IOrderService",
                OperationName = "StartOrder",
                CorrelatesWith = HandleToCorrelate,
                ProtectionLevel = System.Net.Security.ProtectionLevel.None,
                SerializerOption = System.ServiceModel.Activities.SerializerOption.DataContractSerializer,
                DisplayName = "Segundo Receive",
                CorrelatesOn = new MessageQuerySet
                                {
                                    { "key1", new XPathMessageQuery("string('11445')")  }
                                },

                Content = new ReceiveParametersContent()
                {
                    Parameters = { { "orderid", new OutArgument<string>(this.orderid) } }
                },

                CorrelationInitializers =
                        {
                            new RequestReplyCorrelationInitializer
                            {
                                CorrelationHandle = CorrelationHandle,
                            }
                        }
            };



            ReplyCancel = new SendReply
            {
                Request = ReceiveCancel,
                PersistBeforeSend = true,
                Content = SendParametersContent.Create(new Dictionary<string, InArgument> { { "OrderId", new InArgument<string>((env) => "asdf") } })

            };

        }


        protected override void CacheMetadata(NativeActivityMetadata metadata)
        {
            base.CacheMetadata(metadata);
            metadata.AddVariable(this.orderid);
            metadata.AddChild(ReceiveCancel);
            metadata.AddChild(ReplyCancel);
            metadata.AddVariable(CorrelationHandle);
        }


        protected override void Execute(NativeActivityContext context)
        {
            ReceiveCancel.CorrelatesWith = context.GetValue<CorrelationHandle>(HandleToCorrelate);
            context.ScheduleActivity(ReceiveCancel, OnReceiveCompleted);
            Activities.Reverse(0, Activities.Count);
        }

        void OnReceiveCompleted(NativeActivityContext context, ActivityInstance inst)
        {
            foreach (Activity act in Activities)
            {
                context.ScheduleActivity(act);
            }
            context.ScheduleActivity(ReplyCancel);
        }

    }
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜