我有一個簡單的工作流作爲服務託管。我只是想處理這個工作流程中的異常。Windows工作流服務 - 定製服務主機。處理工作流事件
我的工作流將'string'作爲參數並嘗試將其轉換爲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,並且每當工作流引發異常時,調試器都不會中斷任何事件處理程序。 你知道如何正確地做到這一點嗎?