Exercise 3: Applicant Screening

Due to the high volume of résumés that Contoso receives, they want to automate a portion of the résumé screening process. In this exercise, you will send a message to a Flowchart Workflow Service that screens candidates based on education, and then you will notify the HR reviewer of applications that need review by a human.

Task 0 – Opening the Solution

To begin this exercise, you can use the solution you finished from Exercise 2. Alternatively, you can follow the following steps to begin with Exercise 3.

  1. Start Microsoft Visual Studio 2010 from Start | All Programs | Microsoft Visual Studio 2010.
  2. Open the starting solution for Exercise 3 located under the \Source\Ex3\Begin folder (choosing the folder that matches the language of your preference.) Use it as the starting point for this exercise.
  3. Press CTRL+SHIFT+B to build the solution.

Task 1 – Adding the Education Screening Activity

In this task, you will add an existing activity that screens résumés based on the level of education.

  1. Open ScreenEducation.xaml file of the HRApplicationServices.Activities project and explore it. This activity is implemented as a Flowchart that will be used to automatically screen out applicants based on the level of education. While the other activities in our HRApplicationServices.Activities library were implemented in code, this activity is implemented in XAML. You can create and share activities implemented in code or XAML using the Workflow Designer.

    Figure 31

    The ScreenEducation Flowchart

Task 2 – Calling the ScreenEducation Activity

  1. Open SubmitApplication.xamlx.
  2. Expand the Screen Applicant sequence.
  3. Add a new variable EducationPassed of type Boolean to the Screen Applicant scope. To do this:
    1. Click the Variables button
    2. Click on Create Variable
    3. Name the variable EducationPassed
    4. In the type select Boolean
  4. From the HRApplicationServices.Activities group drop a ScreenEducation activity onto the Screen Applicant sequence and set the following properties:
    1. Display Name: Auto Screen Education
    2. Education: ApplicationRequest.Resume.Education
    3. EducationPassed: EducationPassed

Task 3 – Conditionally Notifying a Human Reviewer

Not all applicants will pass the education screening. For those that do not, you need to update the database and notify them. For those that do pass you need to notify a human reviewer to check the application and make a decision.

  1. Drop an If activity from the Control Flow group below the Auto Screen Education activity and set its properties:
    1. Display Name: If Education Screen Passed
    2. Condition: EducationPassed
  2. If the applicant failed the education screen, you will simply update the database. Drop an UpdateHireApproved activity from the HRApplicationServices.Activities group on the Else part of the If activity and set the properties. The Hire variable defaulted to False so the applicant will not be hired in this branch.
    1. Display Name: Update No Hire
    2. ApplicantID: ApplicationResponse.ApplicationID
    3. HireApproved: Hire
  3. If the applicant passed the education screen you need to notify a human reviewer and wait for a response. Drop a Sequence activity from the Control Flow group on the Then part of the If activity and set the properties.
    1. Display Name: Human Screening
  4. You need to send an email to the HR Administrator to let them know there is an application to review. To do this, drop the RequestHumanScreening activity from the HRApplicationServices.Activities group to the Human Screening sequence and set the properties.
    1. Display Name: Request Human Screening
    2. ApplicationID: ApplicationResponse.ApplicationID
    3. ApplicationRequest: ApplicationRequest
  5. Now you need to wait for a response from the HR Administrator. They will be using a web page to send a message to your workflow with the result of the screening. Drop a TransactedReceiveScope activity from the Messaging group below the Request Human Screening activity and set the properties.
    1. Display Name: When Human Screening Complete
  6. Add a variable HumanScreening of type HumanScreeningResult to the When Human Screening Complete scope.
  7. Drop a Receive activity from the Messaging group in the Request area and set the following properties:
    1. Operation Name: HumanScreeningCompleted
    2. Service Contract Name: {https://contoso.com/hr/}IApplicationService
    3. Content: Click to display the Content Definition dialog and set the Message data to HumanScreening
  8. Because this message is sent to a workflow that already exists you must use correlation to provide a way for the WorkflowServiceHost to locate the correct workflow instance. To establish correlation for this Receive activity, do the following.

    1. CorrelatesOn: Click to display the CorrelatesOn Definition dialog
    2. CorrelatesWith: ApplicationIDHandle
    3. Key: Double-click the AppID : Int32 value
    4. Click OK to dismiss the dialog

    Figure 32

    The Correlation definition for the Human Screening Receive activity

  9. Once the message is received you need to update the database and send a reply. Since you have more than one activity in the Body drop a Sequence and set the following property:
    1. Display Name: Update Human Screening Result
  10. Now you can set the actual Hire value from the human screening result. Because Hire was initialized to False, the only way Hire is actually set to true is if the applicant passes both automated and human screening. Drag an Assign activity from the Primitives group and drop it into the Update Human Screening Result sequence and set the properties.
    1. Display Name: Assign Hire
    2. To: Hire
    3. Value: HumanScreening.HiringApproved
  11. Drop an UpdateHireApproved activity from the HRApplicationServices.Activities group below the Assign Hire activity and set the properties.
    1. Display Name: Update Hire Result
    2. ApplicantID: ApplicationResponse.ApplicationID
    3. HireApproved: Hire
  12. Now you need to send a response to the web application. To create a SendReply activity, right-click the Receive activity, and select Create SendReply. Because the Receive activity is inside the Request area and the reply cannot be placed there the SendReply activity will be placed on the clipboard.

    Figure 33

    Create a SendReply for the receive

    Figure 34

    Worflow Designer message saying that the SendReply activity was copied to the clipboard

  13. Paste the SendReply below the Update Hire Result activity and set its properties.

    1. Display Name: Send Human Screening Reply
    2. Content - Message data: True

    Figure 35

    Human Screening Completed

  14. From the menu select Build / Build Solution (CTRL+SHIFT+B).

Task 4 – Sending Human Screening Results

The HireApproval.aspx page will need to call the SubmitApplication.xamlx workflow. Even though they are in the same website the way you call into the workflow is by sending it a message. In this task, you will modify the page to send the hire message.

  1. Next we need to Add a Service Reference to send a message to the receive activity of the SubmitApplication.xamlx workflow that is waiting for the human screening result. To do this right-click the HRApplicationServices project and select Add Service Reference.
  2. In the Add Service Reference dialog click Discover to find the service SubmitApplication.xamlx.
  3. Name the service reference Application, and click OK to generate the reference. After the proxy was generated by Visual Studio, make sure that the Web.config file has the following endpoint configuration.

    XML

    <endpoint address="https://localhost:62305/SubmitApplication.xamlx" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IApplicationService" contract="Application.IApplicationService" name="BasicHttpBinding_IApplicationService" />

  4. In the HRApplicationServices project, right-click HireApproval.aspx, and select View Code (F7).
  5. Add the following namespace directives.

    (Code Snippet – Introduction to WF Services Lab – HireApprovalNamespace CSharp)

    C#

    using HRApplicationServices.Contracts; using HRApplicationServices.Application;

    (Code Snippet – Introduction to WF Services Lab – HireApprovalNamespace VB)

    Visual Basic

    Imports HRApplicationServices.Contracts Imports HRApplicationServices.Application

  6. Locate the SendHumanScreenComplete method, and modify the code as shown.

    (Code Snippet – Introduction to WF Services Lab – SendHumanScreenComplete CSharp)

    C#

    private void SendHumanScreenComplete(bool hire)
    FakePre-cca340d3c7824be39f57fe8b1408cdbb-a3566ce6649b46848e1838ed98b6ea9b ApplicationServiceClient proxy = new ApplicationServiceClient(); try { // Create the result HumanScreeningResult result = new HumanScreeningResult() { AppID = Convert.ToInt32(LabelAppID.Text), HiringApproved = hire, }; // Wrap it in a request HumanScreeningCompletedRequest request = new HumanScreeningCompletedRequest(result); // Call the workflow service proxy.HumanScreeningCompleted(result); proxy.Close(); } catch (Exception) { proxy.Abort(); throw; } FakePre-8382aca7a2a54c2a95d779a69846590d-dc2a34e570bd4f0ea5794209eedde408FakePre-74881496127b437fa9fa91c81b93dbfb-7ace620250024377a5e5325d972eccf1FakePre-af9de4b019004228abebc7bd26efd39c-1b7744dc88f94e7496c7f70f4906e111FakePre-fa924518bb8e4623afcef87c99eded47-1ec34a6dd8d94b73975f7c49d19e0b09

    (Code Snippet – Introduction to WF Services Lab – SendHumanScreenComplete VB)

    VB

    Private Sub SendHumanScreenComplete(ByVal hire As Boolean)
    Dim proxy As ApplicationServiceClient = New ApplicationServiceClient() Try Dim result As New HumanScreeningResult With { .AppID = Convert.ToInt32(LabelAppID.Text), .HiringApproved = hire } proxy.HumanScreeningCompleted(result) proxy.Close() Catch ex As Exception proxy.Abort() Throw End TryFakePre-e66ea7e6e4ea4fbfb77377e4a8641c1b-095998d8735b468981e4923d931a9458

  7. Press CTRL+SHIFT+B to build the solution.

    Note:
    If you are using Visual Basic and get a compilation error stating that the ApplicationServiceClient type is not defined, add the SubmitApplication.vb file located at Assets\VB\HRApplicationServices to the HRApplicationServices project.

Next Step

Exercise 3: Verification