Share via


Walkthrough: Implementing a Service by Using a Category Workflow

This walkthrough creates a category workflow to retrieve the current temperature of a city. The walkthrough creates two specific workflows that convert that temperature to Celsius or Fahrenheit values. This service implementation therefore allows a client application to request either Celsius or Fahrenheit temperature information, and lets you re-use the code that retrieves the actual values.

The walkthrough implements the category workflow in a BLCategory service project named WeatherInformationBLCategory in a DCS solution named WeatherInformation, and then implements the specific workflows in a BLSpecific service named WeatherInformationBLSpecific. The walkthrough also uses the messages in the WeatherInformationMessages project.

Before you begin

  1. Create a DCS solution in Visual Studio in the E:\Walkthroughs folder. For detailed instructions, see Walkthrough: Creating a DCS Solution
  2. Create the WeatherInformationMessages messages project in the DCS solution. For detailed instructions about how to create the messages project, see Walkthrough: Creating a DCS Messages Project
  3. Customize the GetWeatherRequest and GetWeatherResponseMessage classes and add the fields required by the service. For more information, see Walkthrough: Implementing a Service by Using a Specific Workflow.

Detailed Instructions

To create a BLCategory Service project

  1. In Solution Explorer, right-click BLCategory, point to Add, and then click BL Category.

  2. In the Add New Project dialog box, under Projecttypes, verify that DCS BL VSExtensions is selected, and in the Templates pane, click BL Category.

  3. In the Name box, type WeatherInformationBLCategory, and then click Browse.

  4. In the ProjectLocation dialog box, browse to the E:\Walkthroughs\WeatherInformation\BLCategory folder, and then click OK.

  5. In the Add New Project dialog box, click OK.

  6. The following image shows the Add New Project dialog box.

  7. Dd631928.e1815805-3ce7-44d1-b4b6-dcb96c47bd69(en-us,MSDN.10).png

  8. The Add New Project dialog box configured to create a new BL Category project named WeatherInformationBLCategory in the E:\Walkthroughs\WeatherInformation\BLCategory folder

  9. In the Configure Project dialog box, in the Namespace box, type WeatherInformationNamespace.

  10. In the Class box, type GetTemperatureWorkflow, and then click Next.

  11. The following image shows the Project Configuration page.

  12. Dd631928.17eaf998-f271-4f64-b972-abfc7790ed2e(en-us,MSDN.10).png

  13. The Project Configuration page of the Configure Project dialog box, configured to create a project in the WeatherInformationNamespace namespace, and an operation class named GetTemperatureWorkflow

  14. On the MessagesSelector page, click the ellipsis button (…) adjacent to the Select type of Request message box.

  15. In the Please choose a file dialog box, browse to the E:\Walkthroughs\WeatherInformation\Messages\WeatherInformationMessages\bin\Debug folder, click WeatherInformationMessages.dll, and then click Open.

  16. In the Add New Operation Request/Response dialog box on the Messages Selector page, configure the operation messages as follows, and then click Next:

    • Select type of Request message: GetWeatherRequest
    • Select type of Response message: GetWeatherResponse
    • Select type of Error: WeatherInformationError
    • Select type of Exception: WeatherInformationException
  17. The following image shows the Messages Selector page.

  18. Dd631928.b6efe15c-e632-4c8a-9076-b3505239acb8(en-us,MSDN.10).png

  19. The Message Selector page of the Add New Operation Request/Response dialog box, configured to set the Request message to GetWeatherRequest, and the Response message to GetWeatherResponse

  20. On the Messages Assemblies References page, in the Assemblies References list, verify that the WeatherInformationMessages(Project) item is selected, and then click Finish.

  21. The following image shows the Messages Assemblies References page.

  22. Dd631928.58049919-ba85-4ea5-b9d3-416c5dc7bbc3(en-us,MSDN.10).png

  23. The Messages Assemblies References page of the Configure Project dialog box. Verify that, where possible, Visual Studio selects project links for any associated assemblies. These references will automatically update when a change occurs in the associated project

Visual Studio generates the template project and category operation code in the BLCategory folder. You can customize the workflow file and implement the functionality.

To implement workflow functionality in a category workflow

  1. In Solution Explorer, under WeatherInformationBLCategory, in the GetTemperature folder, right-click the GetTemperatureWorkflow.cs file, and then click View Designer.

  2. In the workflow designer, drag a Code activity from the toolbox onto the designer surface, and drop it at the top of the workflow sequence.

  3. Change the activity (Name) property to retrieveCityTemperature, and then double-click the activity to create an event handler.

  4. Visual Studio opens the GetTemperatureWorkflow.cs code-behind file, and creates a new event handler method in the file.

  5. Inside the RetrieveCityTemperature_ExecuteCode method, add code to set the Temperature property of the Response message to 23. This simulates retrieving the real city temperature from a data source such as another Web service or database.

  6. Your code should resemble the following example.

  7. private void retrieveCityTemperature_ExecuteCode(object sender, EventArgs e)
    {
        this.Response.Temperature = 23;
    } 
    
  8. Switch back to the workflow designer.

  9. From the toolbox in the DCS tool group, drag an InsertSpecialisticWorkflow activity onto the designer surface, and drop it below the retrieveCityTemperature activity.

  10. Change the activity (Name) property to convertRetrievedTemperature.

  11. Your workflow should resemble the following image.

  12. Dd631928.057d19d0-7298-4202-ab4c-9ed2bf0e9262(en-us,MSDN.10).png

  13. A BLCategory sequential workflow implementation containing a single CodeActivity activity and an InsertSpecialisticWorkflowActivity activity

  14. On the Build menu, click Build WeatherInformationBLCategory .

Note

You must build your BLCategory workflow project before you implement specific functionality to invoke it. Visual Studio uses reflection on the compiled project assembly to determine the required operation contract to extend.

You can now implement a BLSpecific service that invokes the category workflow functionality when it executes. You must first create the BLSpecific project

To create a new BLSpecific service project

  1. In Solution Explorer, right-click the BLSpecific folder, point to Add, and then click BL Specific.

  2. In the Add New Project dialog box, in the Templates list, click BL Specific.

  3. In the Name box, type WeatherInformationBLSpecific, and then click Browse.

  4. Note

    If you have already created the project named WeatherInformationBLSpecific, then select a different name for this project.

  5. In the Project Location dialog box, browse to E:\Walkthroughs\WeatherInformation\BLSpecific, and then click OK.

  6. The following image shows the Add New Project dialog box.

  7. Dd631928.bb4f2544-f0ef-4252-ba50-0b7c143213d1(en-us,MSDN.10).png

  8. The Add New Project dialog box, configured to create a new BL Specific project named WeatherInformationBLSpecific, in the E:\Walkthroughs\WeatherInformation\BLSpecific folder

  9. In the Add New Project dialog box, click OK.

  10. In the Create New BLSpecific dialog box, in the Namespace box, type WeatherInformationNamespace

  11. In the Service Name box, type WeatherInformationService, and then click Finish.

  12. The following image shows the Create New BL SpecificProject dialog box.

  13. Dd631928.21f1db41-2abf-4c84-a98e-f3f7eb9d19fa(en-us,MSDN.10).png

  14. The Create New BL Specific Project dialog box, configured to create the new project in the WeatherInformationNamespace, and create a service instance named WeatherInformationService

After you create the BLSpecific project, you use the Add New Operation from WF Assembly recipe to create a specific operation that invokes category workflow functionality.

To create a specific workflow to invoke category workflow functionality

  1. In Solution Explorer, in the BLSpecific folder, right-click WeatherInformationBLSpecific, and then click Add New Operation from WF Assembly.

  2. In the Add New Operation from WF Assembly dialog box, in the OperationName field, type GetTemperatureInFahrenheit, and then click Next.

  3. On the Assembly or Project page, click Project, and then in the Projects list, make sure that WeatherInformationBLCategory.csproj is selected.

  4. Note

    This walkthrough assumes that you have created the BLCategory and BLSpecific projects in the same solution.

  5. In the Workflows list, make sure that WeatherInformationNamespace.GetTemperatureWorkflow is selected, and then click Next.

  6. The following image shows the Assembly or Project page.

  7. Dd631928.c0f93cda-1f8a-4623-838a-bf12a696be7f(en-us,MSDN.10).png

  8. The Assembly or Project page of the Add New Operation from a WF Assembly dialog box, configured to select the WeatherInformationBLCategory project from the local solution, and to extend the WeatherInformationNamespace.GetTemperatureWorkflow category workflow from that project

  9. On the Messages Selector page, click the ellipsis button (…) adjacent to the Select type of Request message box.

  10. In the Please choose a file dialog box, browse to the E:\Walkthroughs\WeatherInformation\Messages\WeatherInformationMessages\bin\Debug folder, click WeatherInformationMessages.dll, and then click Open.

  11. In the Add New Operation from WF Assembly dialog box, verify that the correct messages are selected in each list, and then click Next.

  12. Note

    Because the dialog uses reflection to examine the category workflow, you should not have to change any of the message options. The dialog selects the correct messages based on the class type defined for each message in the category workflow.

  13. On the WF Assembly References Selector page, click Next.

  14. On the Messages AssembliesReferences page, click Finish.

Visual Studio generates the operation code and task implementation files in the GetTemperatureInFahrenheit folder.

Note

When you implement a specific workflow operation from a category workflow, the workflow file in the specific task implementation takes the name of the InsertSpecialisticWorkflow activity that you added to the category workflow. In this instance, although the operation name is GetTemperatureInFahrenheit, the workflow file name is convertRetrievedTemperature.cs, which matches the (Name) property of the InsertSpecificWorkflow activity in the WeatherInformationCategoryService.cs workflow.

After you create the operation and task implementation, you can customize the workflow to implement the required functionality.

To implement workflow functionality in a specific workflow

  1. In Solution Explorer, under WeatherInformationBLSpecific, in the GetTemperatureInFahrenheit folder, right-click the convertRetrievedTemperature.cs file, and then click View Designer.

  2. In the workflow designer, drag a Code activity from the toolbox onto the designer surface, and drop it at the top of the workflow sequence.

  3. Change the activity (Name) property to convertTemperature, and then double-click the activity to create an event handler.

  4. Visual Studio opens the convertTemperature.cs code-behind file, and creates a new event handler method.

  5. Inside the RetrieveCityTemperature_ExecuteCode method, add code to convert the Response.Temperature value into Fahrenheit.

  6. Note

    To convert Celsius to Fahrenheit, multiply the Celsius value by 9, divide the result by 5, and add 32. You can assume that the category workflow implementation returns temperatures in Celsius.

  7. Your code should resemble the following example.

  8. private void convertTemperature_ExecuteCode(object sender, EventArgs e)
    {
        double _temperature = Response.Temperature;
        _temperature *= 9;
        _temperature /= 5;
        _temperature += 32;
        Response.Temperature = Convert.ToInt32(_temperature);
    } 
    
  9. Switch back to the workflow designer

  10. From the toolbox in the DCS tool group, drag a SendResponse activity onto the designer surface, and drop it below the convertTemperature activity.

  11. Change the activity (Name) property to sendResponse.

  12. Bind the activity Response property to the workflow Response property:

    1. Click the Response property, and then click the ellipsis button (…) that appears.
    2. In the Bind 'Response' to an activity's property dialog box, on the Bindto an existing member tab, click Response, and then click OK.
  13. On the Build menu, click BuildWeatherInformationBLSpecific.

You have now implemented a DCS BLCategory operation, and a BLSpecific project containing a specific workflow that invokes that operation. To implement multiple category workflows to implement the same category operation, repeat the steps for creating and implementing a specific workflow, modifying the specific workflow to implement the required functionality. After you finish implementing the service, you can deploy the project and create a client application to invoke the service operations. For more information about deploying DCS Services, see Walkthrough: Deploying DCS Services by Using Visual Studio. For more, see Building Client Applications.

See Also

Walkthrough: Creating a DCS Solution

Walkthrough: Creating a DCS Messages Project

Walkthrough: Deploying DCS Services by Using Visual Studio

Building Client Applications