.NET Framework Developer Center > .NET Development Forums > Windows Workflow Foundation > Is workflow appropriate for this requirement?
Ask a questionAsk a question
 

AnswerIs workflow appropriate for this requirement?

  • Friday, September 18, 2009 5:08 AMhitchness Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Is workflow appropriate for this requirement?

    I'm working on a system where currently there is a requirement for the implementation of a questionnaire engine - while it is basically just a questionnaire, activities need to be triggered elsewhere in the system based on the answers to the question, and also data may need to be retrieved from elsewhere in the system to create the questions. It is also necessary to implement logic such as "if the answer to question 2 is (a) go to question 3, else if it is (b) go to question 5". Or "If >3 of the first 5 questions are answered with a Yes, update a status in the database".

    It is also necessary for the user to have a reasonable amount of control over the structure of the questions, and to be able to create new questions.

    While questionnaires are the initial requirement, the design is being looked at from the point of view of expanding this in future to a general rules engine for carrying out processes requiring human interaction, elsewhere in the future.

    I'm wondering whether WF is an appropriate framework to use to design this - it certainly seems to be on face value - rehost the designer, and users can build their own requirements, there are activities allowing the creation of custom flow etc. But I'm wondering if WF may be overkill for the requiremnt, or may add a level of complexity.

    Would it be appropriate to have a number of basic custom activities that a user can drag and drop and rearrange with properties such as "Question", "Answers", "Answer Type" (multi choice, Y/N, free text), "set business object field", "retrieve business object data" etc.?

    This WF implementation would need to be driving a UI - most likely silverlight - to display the questons and capture the answers from the user.

    I've done quite a bit of reading on WF, and played with a few samples, but am just not sure it's appropriate for this requirement, and was hoping for some insight from those who've made more extensive use of it.

Answers

  • Tuesday, September 22, 2009 12:41 PMRyan Vice Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    I'm not sure if I fully understand the requirements but to me it seems like you don't need a dynamic path and that WF would be an appropriate fit. Create a CA (custom activity) that allows for asking of a question. I'd probably do it where the questions are stored in the DB and the CA takes a DB ID (or you can populate the CA at design time from the DB depending on your environements for dev and testing). Then to get the results you'd need an event that would have a custom ExternalDataExchangeEventArgs derived event args which would pass the answer back to the WF where you have separate CAs for each business logic need (updating user record, ect...) and conditionally fire the correct activity based on the results that come back in your event.

    If this sounds like a good option and you need help working through the design more just post up more questions and clarify the requirments more.
    If my response answers your question, please mark it as the "Answer" by clicking that button above my post.
  • Wednesday, September 23, 2009 4:54 PMguptashail Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    Workflow can be used to any business problem where you have a "Work flow" i.e. flow of activities. So if you can break down your business processes in the form of activities, you can use workflow. The benefit of WF is that it can be serialized as one big object and stored inside a persistence store. It preserves all its conditions, states and variables.

    In your case I think this can be an excellent tool to give users the option to design their own business workflows. End users/business users are sometimes very good at defining the processes and lots of them use workflow designing tools like Visio/flow diagram in word or PowerPoint. Then someone needs to understand that workflow and code it for them. What WF can do here is act as an excellent tool which gives the freedom of Visio designs and yet the power of a coded application.

    Your answering application can also be designed using workflow. Imagine that a user taking exam wants to pause; here your workflow can persist with the status of last question/total questions etc. and resume when ever the user wants it to. Regarding the dynamic set of questions, there are many ways to solve it, like:

    1) You can create a simple workflow that evaluates a boolean condition of true of false and check if the current question and answer matches or not. Then it can loop through all the questions to complete the test or terminate if the user has answered a wrong question or what ever condition you want.

    2) You can create a dynamic workflow to take decisions at runtime. Study more on Activity Context at runtime and dynamic workflows for this.

    3) You can use a rule based engine from a XOML file to create a dynamic workflow.

    Hope all this helps you decide...

All Replies

  • Friday, September 18, 2009 9:14 AMGeert van Horrik Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    If you need to make choices, based on a fixed path, then WF is appropriate. However, since you describe that the user should be able to create new questions (and thus paths) at runtime, I recommend you to create a simpler item without workflow like below (the main steps described can be loaded into a workflow, but I think that is overkill):

    1) Retrieve the questions
    2) Now create a generic window or control that shows the question, and asks the question provider for the next question. The question provider should determine, based on the runtime conditions that the user has entered, whether to return a new questions or not (then the questionnaire is finished).
    3) Send the data

    In other words: I wouldn't use WF in this scenario.
    Geert van Horrik - CatenaLogic
    Visit my blog: http://blog.catenalogic.com

    Looking for a way to deploy your updates to all your clients? Try Updater!
  • Monday, September 21, 2009 2:27 PMRyan Vice Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    When you say the user needs to be able to create new questions does this also mean that they need to be able to setup the conditional logic on how the WF will proceed after the question is answered?
    If my response answers your question, please mark it as the "Answer" by clicking that button above my post.
  • Tuesday, September 22, 2009 12:07 PMhitchness Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Yes, that's correct. e.g. they need to be able to specify:

    What colour is your hair?

    If = Red go to question 5
    If = blonde go to question 9
    If = black, update hair colour on person record in DB and end.

    (where Update field blah would be another activity)
  • Tuesday, September 22, 2009 12:41 PMRyan Vice Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    I'm not sure if I fully understand the requirements but to me it seems like you don't need a dynamic path and that WF would be an appropriate fit. Create a CA (custom activity) that allows for asking of a question. I'd probably do it where the questions are stored in the DB and the CA takes a DB ID (or you can populate the CA at design time from the DB depending on your environements for dev and testing). Then to get the results you'd need an event that would have a custom ExternalDataExchangeEventArgs derived event args which would pass the answer back to the WF where you have separate CAs for each business logic need (updating user record, ect...) and conditionally fire the correct activity based on the results that come back in your event.

    If this sounds like a good option and you need help working through the design more just post up more questions and clarify the requirments more.
    If my response answers your question, please mark it as the "Answer" by clicking that button above my post.
  • Wednesday, September 23, 2009 4:54 PMguptashail Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    Workflow can be used to any business problem where you have a "Work flow" i.e. flow of activities. So if you can break down your business processes in the form of activities, you can use workflow. The benefit of WF is that it can be serialized as one big object and stored inside a persistence store. It preserves all its conditions, states and variables.

    In your case I think this can be an excellent tool to give users the option to design their own business workflows. End users/business users are sometimes very good at defining the processes and lots of them use workflow designing tools like Visio/flow diagram in word or PowerPoint. Then someone needs to understand that workflow and code it for them. What WF can do here is act as an excellent tool which gives the freedom of Visio designs and yet the power of a coded application.

    Your answering application can also be designed using workflow. Imagine that a user taking exam wants to pause; here your workflow can persist with the status of last question/total questions etc. and resume when ever the user wants it to. Regarding the dynamic set of questions, there are many ways to solve it, like:

    1) You can create a simple workflow that evaluates a boolean condition of true of false and check if the current question and answer matches or not. Then it can loop through all the questions to complete the test or terminate if the user has answered a wrong question or what ever condition you want.

    2) You can create a dynamic workflow to take decisions at runtime. Study more on Activity Context at runtime and dynamic workflows for this.

    3) You can use a rule based engine from a XOML file to create a dynamic workflow.

    Hope all this helps you decide...

  • Wednesday, September 23, 2009 6:24 PMRyan Vice Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I agree with most things said in this thread but I would like to point out that in our system we've found a huge disconnect in what non-programmers can do in Visio and creating actual working WF definitions. I'm sure if you put enough code into it on rehosting the designer you might be able to get better results but I think visualization and the better communication it can provide between analyst and coders is the best realistic expectation for a modest sized project.
    If my response answers your question, please mark it as the "Answer" by clicking that button above my post.
  • Wednesday, October 07, 2009 5:16 AMhitchness Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Thanks for all of the responses. I'm actually starting to look at WF4, as I'll be using this if the development goes ahead - ceratainly a few changes from 3.5 -> 4. I'm just wondering what the best way would be to implement this in a bit of a disconnected manner.

    Ideally there will be a silverlight interface presenting the steps to the user. The user will then enter their response and click next, which will "submit" the response to the workflow, which should then determine the next step i.e.:
    • display next question based on decision logic using answer from previous question, or
    • update value on business object based on response, display next question, or
    • retrieve/calculated value from elsewhere in the system and display next question, or
    • terminate
    • etc..
    Given that the UI will most likely be Silverlight and it's not possible to run workflows in Silverlight, would it be best to execute the workflow on the server and then expose it using WCF?

    Should I be using bookmarks to implement the asynchronous processing of the workflow?
    If bookmarksare used, would the theory be that the bookmark is created and the workflow is persisted at the end of each step when the question is displayed to the user?
    If not bookmarks, then what?

    Thanks again.
  • Wednesday, October 07, 2009 11:48 AMRyan Vice Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hosting

    You have 3 options
    1 - Host it as a web service: http://www.microsoft.com/uk/msdn/screencasts/screencast/25/Windows-Workflow-Foundation-Exposing-Web-Services.aspx
    2 - Host it as a WCF workflow service: http://www.microsoft.com/uk/msdn/screencasts/screencast/25/Windows-Workflow-Foundation-Exposing-Web-Services.aspx
    3 - Host it in Silverlight. I don't know enough about silverlight to know the details but in ASP.Net you put your WorkflowRuntime setup and teardown code in Global.asax Application_Start and Application_End
    4 - Host the runtime in a WindowsService

    1-3 are the easier options but it's really your preference.

    It is correct that you would use bookmarks to get asynchronous behaivor at a low level but talking at a higher level, use the HandleExternalEventActivity and CallExternalMethodActivity in conjunction with the ExternalDataExchange service and your own custom local service to communicate from WF. I'm almost done with an article that covers this technique and I'll post it up here when I get it done.
    If my response answers your question, please mark it as the "Answer" by clicking that button above my post.
  • Tuesday, October 13, 2009 3:04 AMhitchness Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    It's necessary that if (eg) a user gets to question 10 and decides that question 3 was answered incorrectly, they jump back to question 3 and continue from there. Does this imply (in the flowchart style WF in .Net 4) a return path between every state and all prior states? Would it be possible/easier to maintain a list of the answers, and start a new workflow, replaying the answers up to the point the user wants to continue from? How would this best be implemented?
  • Wednesday, October 14, 2009 4:11 PMguptashail Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    the best way to implement this will be to maintain the question and answer sheet in a DB. The structure could be like - Questions Table -> Answers Table with One to Many relation between question and user's answers.

    The workflow can be used to control the flow of work done here like - initiate the test, control where to start and stop the test, record answers in DB, throw a question, restart from any question and record new answers, play all the answers with the status as "recent answer" etc.

  • Friday, October 23, 2009 5:32 AMhitchness Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi Ryan,

    I just wondered if you'd finished the article you mention above yet? I'd be quite interested to have a read.
  • Friday, October 23, 2009 1:52 PMRyan Vice Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    http://www.ryanvice.net/uncategorized/using-externaldataexchange-service-in-wf-3-5/

    Here you go and I'd love some feedback on it. If you find things confusing about it send me an email from the about page.
    If my response answers your question, please mark it as the "Answer" by clicking that button above my post.

    My blog: http://www.RyanVice.net/
  • Friday, November 06, 2009 2:40 PMRyan Vice Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    http://www.ryanvice.net/uncategorized/using-externaldataexchange-service-in-wf-3-5/

    Here you go and I'd love some feedback on it. If you find things confusing about it send me an email from the about page.
    If my response answers your question, please mark it as the "Answer" by clicking that button above my post.

    My blog: http://www.RyanVice.net/

    The path to the article is now: http://www.ryanvice.net/wf3-5/using-externaldataexchange-service-in-wf-3-5/
    If my response answers your question, please mark it as the "Answer" by clicking that button above my post.

    My blog: http://www.RyanVice.net/