为什么 SqlTrackingService 不能与 WF 4.0 一起使用?
在 Workflow Foundation 3.5 中,我们可以使用 SqlTrackingService 跟踪数据,但在 WF 中它不起作用:当尝试使用它时,SqlTrackingService 不会捕获任何工作流或活动事件。
有没有办法在 WF 4.0 中配置 SqlTrackingService 而无需编写自定义跟踪服务? 重点是我想使用尽可能多的内置工具(例如 MS 示例中的 WorkflowMonitor)
以下是两个示例:
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();
}
}
}
In Workflow Foundation 3.5 we could track data with SqlTrackingService, but in WF it doesn't work: when trying to use it SqlTrackingService doesn't catch any workflow or activity event.
Is there any way to configure SqlTrackingService in WF 4.0 without writing custom tracing service? The point is I want to use as much built-in tools as possible (like WorkflowMonitor from the MS samples)
Here are two examples:
WF3.5 (works perfectly, notice that My3Activity must be compiled as .NET 3.5 Workflow Activity Library)
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 (doesn't raise any events or probably they are not catched by tracking service; this time MyActivity is .NET 4.0 WF Activity Library)
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();
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
WF3和WF4之间没有关系。后者是完全重写的,并且不与之前的 WF3 共享任何类型。因此,.NET 4 中的 SqlTrackingService 仅适用于 WF3。
您的第二个代码示例是 WF3 和 WF4 类型的有趣组合。 WorkflowApplication 是 WF4,而使用的 WorkflowRuntime 是 WF3。邮寄这些根本没有任何意义。
如果它是 WF4,代码应该如下所示:
There is no relation between WF3 and WF4. The latter is a complete rewrite and doesn't share any types with the previous WF3. As a result the SqlTrackingService in .NET 4 only works with the WF3.
Your second code example is an interesting mix of WF3 and WF4 types. The WorkflowApplication is WF4 while the WorkflowRuntime used is WF3. Maixing these doesn't make any sense at all.
If it is intended to be WF4 the code should look something like this: