This post is for the developer just getting started with WF and will walk through creating a “hello world” WF console application from scratch. The below example is using Visual Studio 2013 and framework .net 4.5.
Step 1 – Create new project
Open up visual studio and select new project, under templates select your choice of language and then the workflow template type. There are four workflow templates to choice from but for this example we will choose “Workflow Console Application” which will create all the scaffolding needed for us to create our first WF flow.
Step 2 – Adding activities
After the project has been created a new activity design service will open up called workflow1.xaml. The toolbox holds all the built in WF activities that are available for us to use plus as you would expect you are also able to create your own which we will cover in a later post. From the toolbox navigate to the “control flow” category and drag a sequence activity on to the design service. Your WF flow should currently look like the below.
With WF you are able to add activities to other activities which allows you to build up your application in blocks, so next navigate to the “primitives” category and drag a WriteLine activity onto the sequence activity, within the WriteLine activity enter the string “Hello World” and your design service should now be similar to below.
When the flow is executed it will execute the children of the sequence activity in “sequence”, but as this example is quite simple with only one child only the WriteLine activity will be executed.
Step 3 – Adding code to execute the WF flow
We have created our first WF flow and now we need to create the csharp or vb code to execute it, by adding the “WorkFlow Console Application” like we have visual studio has already added most of the code required to execute the default workflow1.xaml flow, we just need to add a single line so we can stop the console application closing before we can read our customary Hello World message.
In the solution explorer navigate to and select Module1, you will see the default Module1 code and we just need to add a Console.ReadKey command to the end of the default procedure to stop the console window closing. If you are using Visual Basic then your code should look like the below.
Step 4 – Execute Flow
We have now finished your first Hello World console WF application, save the solution and run the solution. You should then hopefully see a console window appear with the words Hello World displayed, as per the below.
Congratulations if thats your first WF flow, now why not try playing around by adding additional WriteLine activities and changing the text for the fun of it.