Invoke Workflow (WF) using Task-based Asynchronous Pattern (TAP) in ASP.NET MVC
While facing a scenario where-in I wanted to invoke a workflow asynchronously from the controller/action method, I did not come across a solution which uses Task-based Asynchronous Pattern (TAP). The best one so far I saw was this. However it uses AsyncController instead of the new “async” pattern. Thus, I gave up googling around and came-up with the following approach: –
I am using ProDinner as an example base to demo my approach. Say the user is on the list of meals view (as shown below) and wants to check the deal at local grocery store for that item. (the check deal functioning is not foolproof). I have created a CodeActivity namely GetDeal which takes in ItemName and Zip as InArgument(s) and spits out IEnumerable<Deal> as OutArgument. I’ve mentioned details on how I make the web api call using the new HttpClient within the AsyncCodeAcitivity in my next blog post.
Here’s the code snippet which demonstrates the invoking of workflow activity GetDeal –