您可以想象一个公开接收活动的 xaml 服务。这是我工作流程中的第一个活动。在这个接收背后有一些简单的活动,如 InitializateCorrelation”、“assign”、“delay”......等等。然后我有一个由活动设计器制作的自定义活动。所以我的主要工作流程中确实有一个代码活动。这个提供拖放区以允许开发人员自定义活动。但我希望此活动首先具有固定的接收活动。此接收必须使用第一个相关句柄进行相关,该句柄是使用在第一次接收中获得的信息初始化的服务。
我的问题是我无法使用在 xaml 中初始化的相关句柄来关联代码活动中的接收。当我调用第二个接收(代码接收)时出现超时错误。
你知道出了什么问题吗?
这是我的代码活动的代码
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);
}
}
}