在Workflow Foundation 3.5中,我们可以使用SqlTrackingService跟踪数据,但在WF中它不起作用:当尝试使用它时,SqlTrackingService不会捕获任何工作流或活动事件。
有没有办法在不编写自定义跟踪服务的情况下在WF 4.0中配置SqlTrackingService?关键是我想尽可能多地使用内置工具(比如MS样本中的WorkflowMonitor)< / p>
以下是两个例子:
WF3.5 (完美无缺,请注意My3Activity必须编译为.NET 3.5工作流程活动库)
namespace WfServiceHost
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Creating workflow runtime...");
using (WorkflowRuntime wr = new WorkflowRuntime())
{
SqlTrackingService ts = new SqlTrackingService("Initial Catalog=Tracking;Data Source=localhost;Integrated Security=SSPI;");
ts.UseDefaultProfile = true;
wr.AddService(ts);
wr.StartRuntime();
Console.WriteLine("Creating workflow instance...");
WorkflowInstance wi = wr.CreateWorkflow(typeof(My3Activity));
Console.WriteLine("Starting workflow instance...");
wi.Start();
Console.WriteLine("Workflow instance started");
Console.WriteLine("Press any key to STOP");
Console.ReadKey();
}
Console.WriteLine("Workflow runtime stopped.");
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
}
}
}
WF4.0 (不会引发任何事件,也可能不会跟踪服务;这次MyActivity是.NET 4.0 WF活动库)
namespace WfServiceHost
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Creating workflow runtime...");
using (WorkflowRuntime wr = new WorkflowRuntime())
{
SqlTrackingService ts = new SqlTrackingService("Initial Catalog=Tracking;Data Source=localhost;Integrated Security=SSPI;");
ts.UseDefaultProfile = true;
wr.AddService(ts);
wr.StartRuntime();
Console.WriteLine("Creating workflow instance...");
MyActivity activity = new MyActivity();
WorkflowApplication app = new WorkflowApplication(activity);
Console.WriteLine("Starting workflow instance...");
app.Run();
Console.WriteLine("Workflow instance started");
Console.WriteLine("Press any key to STOP");
Console.ReadKey();
}
Console.WriteLine("Workflow runtime stopped.");
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
}
}
}
答案 0 :(得分:1)
WF3和WF4之间没有关系。后者是完全重写,不与以前的WF3共享任何类型。因此,.NET 4中的SqlTrackingService仅适用于WF3。
您的第二个代码示例是WF3和WF4类型的有趣组合。 WorkflowApplication是WF4,而WorkflowRuntime使用的是WF3。 Maixing这些根本没有任何意义。
如果它是WF4,代码看起来应该是这样的:
namespace WfServiceHost
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Creating workflow instance...");
MyActivity activity = new MyActivity();
WorkflowApplication app = new WorkflowApplication(activity);
Console.WriteLine("Starting workflow instance...");
app.Run();
Console.WriteLine("Workflow instance started");
Console.WriteLine("Press any key to STOP");
Console.ReadKey();
}
}
}