This sample demonstrates how to implement a business process using messaging activities and two workflows hosted as workflow services. These workflows are part of the IT infrastructure of a fictional company called Contoso, Inc.
HiringRequest workflow process (implemented as a Flowchart) asks for authorization from several managers in the organization. To achieve this goal, the workflow uses other existing services in the organization (in our case, an inbox service and an organizational data service implemented as plain Windows Communication Foundation (WCF) services).
ResumeRequest workflow (implemented as a Sequence) publishes a job posting in Contoso's external careers Web site and manages the acquisition of resumes. A job posting is available in the external Web site for a fixed period of time (until a timeout expires) or until an employee from Contoso decides to remove it.
This sample demonstrates the following features of .NET Framework 4.6.1:
Custom activities (declarative and code-based).
System-provided SQL server persistence.
Event Tracking for Windows (ETW) Tracking.
Composition of activities.
Durable timers (Delay activity).
More than one workflow in the same solution.
The samples may already be installed on your machine. Check for the following (default) directory before continuing.
If this directory does not exist, go to Windows Communication Foundation (WCF) and Windows Workflow Foundation (WF) Samples for .NET Framework 4 to download all Windows Communication Foundation (WCF) and WF samples. This sample is located in the following directory.
Description of the Process
Contoso, Inc. wants to have close control of the headcount in each of its departments. Therefore, anytime any employee wants to start a new hiring process, they need to go through a hiring request process approval before the recruiting can actually happen. This process is called hiring process request (defined in the HiringRequestService project) and consists of the following steps:
An employee (the requester) starts the hiring process request.
The requester’s manager must approve the request:
The manager can reject the request.
The manager can return the request to the requester for additional information:
- The requester reviews and sends the request back to the manager.
The manager can approve.
After the requester’s manager approves, the department owner must approve the request:
The department owner can reject.
The department owner can approve.
After the department owner approves, the process requires the approval of 2 HR managers or the CEO:
The process can transition to the accepted or rejected state.
If the process is Accepted, a new instance of the
ResumeRequestworkflow is started (
ResumeRequestis linked to HiringRequest.csproj through a service reference.)
Once the managers approve the hiring of a new employee, HR must find the appropriate candidate. This process is performed by the second workflow (
ResumeRequest, defined in ResumeRequestService.csproj). This workflow defines the process for submitting a job posting with a career opportunity to Contoso's external Careers Web site, receives resumes from applicants, and monitors the state of the job posting. Positions are available for a fixed time period (until a time expires) or until an employee from Contoso decides to remove it. The
ResumeRequest workflow consists of the following steps:
An employee from Contoso types in the information about the position and a time-out duration. Once the employee types in this information, the position is posted in the Careers Web site.
Once the information is published, interested parties can submit their resumes. When a resume is submitted, it is stored in a record linked to the job opening.
Applicants can submit resumes until the time-out expires or someone from Contoso HR department explicitly decides to remove the posting by stopping the process.
Projects in the sample
The following table shows the projects in the sample solution.
|ContosoHR||Contains data contracts, business objects and repository classes.|
|HiringRequestService||Contains the definition of the Hiring Request Process workflow.
This project is implemented as a console application that self-hosts the workflow (xaml file) as a service.
|ResumeRequestService||A workflow service that collects resumes from candidates until a time-out expires or someone decides that the process has to be stopped.
This project is implemented as a declarative workflow service (xamlx).
|OrgService||A service that exposes organizational information (Employees, Positions, PositionTypes, and Departments). You can think of this service as the Company Organization module of an Enterprise Resource Plan (ERP).
This project is implemented as a console application that exposes a Windows Communication Foundation (WCF) service.
|InboxService||An inbox that contains actionable tasks for employees.
This project is implemented as a console application that exposes a WCF service.
|InternalClient||A Web application for interacting with the process. Users can start, participate, and view their HiringProcess workflows. Using this application, they can also start and monitor ResumeRequest processes.
This site is implemented to be internal to Contoso's intranet. This project is implemented as an ASP.NET Web site.
|CareersWebSite||An external Web site that exposes the open positions in Contoso. Any potential candidate can navigate to this site and submit a resume.|
The following table describes how each feature is used in this sample.
|Flowchart||The business process is represented as a flowchart . This flowchart description represents the process in the same way in which a business would have drawn it in a whiteboard.||HiringRequestService|
|Workflow services||The Flowchart with the process definition is hosted in a service (in this example, the service is hosted in a console application).||HiringRequestService|
|Messaging activities||The flowchart uses messaging activities in two ways:
- To get information from the user (to receive the decisions and related information in each approval step).
- To interact with other existing services (InboxService and OrgDataService, used through service references).
|Content based correlation||Approval messages correlate on the ID property of the hiring request:
- When a process is started, the correlation handle is initialized with the ID of the request.
- Incoming approval messages correlate on their ID (the first parameter of each approval message is the ID of the request).
|HiringRequestService / ResumeRequestService|
|Custom activities (declarative and code based)||There are several custom activities in this sample:
|System-provided SQL Server Persistence||The WorkflowServiceHost instance that hosts the Flowchart process definition is configured to use the system-provided SQL Server persistence.||HiringRequestService / ResumeRequestService|
|Custom Tracking||The sample includes a custom tracking participant that saves the history of a
|ETW Tracking||System-provided ETW Tracking is configured in the App.config file in the HiringRequestService service.||HiringRequestService|
|Composition of Activities||The process definition uses the free composition of Activity. The Flowchart contains several Sequence and Parallel activities that at the same time contain other activities (and so on).||HiringRequestService|
|Parallel Activities||- ParallelForEach<T> is used to register in the Inbox of the CEO and HR Managers in parallel (Waiting for two HR Managers' Approval step).
- Parallel is used to do some clean-up tasks in the Completed and Rejected steps
|Model Cancellation||The Flowchart uses CancellationScope to create cancellation behavior (in this case it does some clean-up.)||HiringRequestService|
|Customer Persistence Participant||
|Transactions||TransactionScope is used to ensure consistency of data within the execution of several activities (when a new resume is received).||ResumeRequestService|
|Transactions||The custom persistence participant (
|Using WF in ASP.NET applications.||Workflows are accessed from two ASP.NET applications.||InternalClient / CareersWebSite|
Data is stored in a SQL Server database called
ContosoHR (the script for creating this database is located in the
DbSetup folder). Workflow instances are stored in a SQL Server database called
InstanceStore (the scripts for creating the instance store are part of the .NET Framework 4.6.1 distribution).
Both databases are created by running Setup.cmd script from a Visual Studio command prompt.
Running the sample
To create the databases
Open a Visual Studio command prompt.
Navigate to the sample folder.
Verify that the two databases
InstanceStorewere created in SQL Express.
To set up the solution for execution
Run Visual Studio as an administrator. Open HiringRequest.sln.
Right-click the solution in Solution Explorer and select Properties.
Select the option Multiple Startup Projects and set the CareersWebSite, InternalClient, HiringRequestService, and ResumeRequestService to Start. Leave ContosoHR, InboxService, and OrgService as None.
Build the solution by pressing CTRL+SHIFT+B. Verify that the build succeeded.
To run the solution
After the solution builds, press CTRL+F5 to run without debugging. Verify that all services have started.
Right click InternalClient in the solution and then select View in Browser. The default page for
InternalClientis displayed. Ensure that services are running, and click the link.
The HiringRequest module is displayed. You can follow the scenario detailed here.
HiringRequestis complete, you can start the
ResumeRequest. You can follow the scenario detailed here.
ResumeRequestis posted, it is available in the public Web site (Contoso Careers Web Site). To see the Job Posting (and apply for the position), navigate to the Careers Web Site.
Right-click CareersWebSite in the solution and select View in Browser.
Navigate back to the
InternalClientby right-clicking InternalClient in the solution and selecting View in Browser.
Go to the JobPostings section by clicking the Job Postings link in the inbox top menu. You can follow the scenario detailed here.
Michael Alexander (Software Engineer) wants to request a new position for hiring a Software Engineer in Test (SDET) in the Engineering department who has at least 3 years of experience in C#.
After being created, the request appears in Michael’s inbox (click Refresh if you do not see the request) awaiting Peter Brehm’s approval, who is Michael’s manager.
Peter wants to act on Michael’s request. He thinks the position demands 5 years of C# experience instead of 3, so he sends his comments back for review.
Michael sees a message in his inbox from his manager and wants to act. Michael sees the history of the position request and agrees with Peter. Michael modifies the description to require 5 years of C# experience and accepts the modification.
Peter acts on Michael’s modified request and accepts it. The request now must be approved by the Director of Engineering, Tsvi Reiter.
Tsvi Reiter wants to expedite the request, so he puts in a comment to say that the request is urgent and accepts it.
The request now has to be approved by two HR managers or the CEO. The CEO, Brian Richard Goldstein, sees the urgent request by Tsvi. He acts on the request by accepting it, thus bypassing the approval by two HR managers.
The request is removed from Michael’s inbox and the process of hiring an SDET has now begun.
Start Resume Request
Now, the job position is waiting to be posted to an external Web site where people can apply (you can see it clicking the Job Postings link). Currently, the job position is sitting with an HR representative who is responsible for finalizing the job position and posting it.
HR wants to edit this job position (by clicking the Edit link) by setting a time-out of 60 minutes (in real life, this could be days or weeks). The time-out allows the job position to be taken off the external Web site according to the time specified.
After saving the edited job position, it appears in the Receiving Resumes tab (refresh the Web page to see the new job position).
The job position should appear on the external Web site. As a person interested in applying for the job, you may apply for this position and submit your resume.
If you go back to the Job Postings List service, you can "view resumes" that have been collected so far.
HR can also stop collecting resumes (for example, once the right candidate has been identified).
Ensure that you are running Visual Studio with administrator privileges.
If the solution fails to build, verify the following:
- The reference to
ContosoHRis not missing from the
- The reference to
If the solution fails to execute, verify the following:
All services are running.
The service references are updated.
Open the App_WebReferences folder
Right-click Contoso and select Update Web/Service References.
Rebuild the solution by pressing CTRL+SHIFT+B in Visual Studio.
Delete the SQL Server instance store by running Cleanup.bat, located in DbSetup folder.
Delete the source code form your hard drive.