我将非常简单的工作流程作为服务托管。我只想处理此工作流程中的异常。
我的工作流程将“字符串”作为参数并尝试将其转换为 int。因此,每当我发送像“asasafs”这样的数据时,它都会失败并引发异常。非常简单 :)
我读过我可以创建自己的 WorkflowServiceHostFactory,但不幸的是我无法完成我的简单任务,这是我的实现:
public class MyServiceHostFactory : System.ServiceModel.Activities.Activation.WorkflowServiceHostFactory
{
protected override WorkflowServiceHost CreateWorkflowServiceHost(Activity activity, Uri[] baseAddresses)
{
return base.CreateWorkflowServiceHost(activity, baseAddresses);
}
protected override WorkflowServiceHost CreateWorkflowServiceHost(WorkflowService service, Uri[] baseAddresses)
{
var host = base.CreateWorkflowServiceHost(service, baseAddresses);
WorkflowRuntimeBehavior wrb = host.Description.Behaviors.Find<WorkflowRuntimeBehavior>();
if (wrb == null)
wrb = new WorkflowRuntimeBehavior();
wrb.WorkflowRuntime.ServicesExceptionNotHandled += WorkflowRuntime_ServicesExceptionNotHandled;
wrb.WorkflowRuntime.Started += WorkflowRuntime_Started;
wrb.WorkflowRuntime.WorkflowCompleted += WorkflowRuntime_WorkflowCompleted;
host.Description.Behaviors.RemoveAll<WorkflowRuntimeBehavior>();
host.Description.Behaviors.Add(wrb);
host.Faulted += host_Faulted;
host.UnknownMessageReceived += host_UnknownMessageReceived;
return host;
}
void workflowRuntime_WorkflowCreated(object sender, WorkflowEventArgs e)
{
throw new NotImplementedException();
}
void WorkflowRuntime_WorkflowCompleted(object sender, System.Workflow.Runtime.WorkflowCompletedEventArgs e)
{
throw new NotImplementedException();
}
void WorkflowRuntime_Started(object sender, System.Workflow.Runtime.WorkflowRuntimeEventArgs e)
{
throw new NotImplementedException();
}
void WorkflowRuntime_ServicesExceptionNotHandled(object sender, System.Workflow.Runtime.ServicesExceptionNotHandledEventArgs e)
{
throw new NotImplementedException();
}
void host_UnknownMessageReceived(object sender, System.ServiceModel.UnknownMessageReceivedEventArgs e)
{
throw new NotImplementedException();
}
void host_Faulted(object sender, EventArgs e)
{
throw new NotImplementedException();
}
}
我正在使用 Visual Studio 2k10 和 iisexpress,每当工作流引发异常时,调试器都不会中断我的任何事件处理程序。你知道如何正确地做吗?