开发者

Windows Workflow Foundation 4 (WF4) Error Handling

What is the best way to g开发者_开发百科et error messages from a WF4 workflow back to a hosting ASP.NET MVC application? I need the workflow to not terminate, but continue to be active, and then pass a message back to the hosting app regarding the error, so the user can take an alternative action, but I'm not sure how to do that.


In order to keep your workflow alive you need to catch the exception in your workflow. Add a TryCatch activity to you workflow and in a Catch block you can use either a Send or a custom activity to send the data to the host application.

The one exception is to use the WorkflowApplication.OnUnhandledException with persistence and specify abort. In that case the in memory state of the workflow is just removed and the workflow can be reloaded for the last persisted state. If you go this way you need to make sure, using the Perist activity, that your workflow is saved whenever something that cannot be redone.


TryCatch is not really enough when it comes to WF4. Also, handling the UnhandledException event from your workflow host doesn't really tell you much about which activity failed and why.

A suggested approapch is to use TryCatch and Activity tracking within WF4. A good summary of this can be found here: http://msmvps.com/blogs/theproblemsolver/archive/2009/11/27/trycatch-activity-in-wf4.aspx

You can extend your workflow host with Tracking participants and with a catch handler that encapsulates your activity that might fault, handle the exception and create a new TrackingRecord that can better illustrate what happened.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜