Share via


Walkthrough: Implementing a DCS Task

This walkthrough implements a DCS task in a WFTasks project. The task accepts a city name in the Request message, simulates retrieving the temperature for that city, and then returns an integer representing the temperature in the city.

The walkthrough implements a task in a new WFTask project named WeatherInformationTasks in a DCS Solution named WeatherInformation. The walkthrough creates the task based on a stub defined in a DCS Stub project named WeatherInformationStubs. For detailed instructions about how to create the WeatherInformationStubs project, see Walkthrough: Implementing a DCS Stub.

Before you begin

  • Create a DCS solution named WeatherInformation in the E:\Walkthroughs folder. For detailed instructions about how to create a DCS Solution project, see Walkthrough: Creating a DCS Solution.

Detailed Instructions

To create a new WFTask project

  1. In the DCS solution, right-click the WFTask folder, point to Add, and then click WF Task.

  2. In the Add New Project dialog box, in the Templates list, click WF Task.

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

  4. In the Project Location dialog box, browse to the E:\Walkthroughs\WeatherInformation\WFTask folder, and then click OK.

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

  6. Dd632063.cc2ae12b-61f9-4760-a4f4-31b303f23f0d(en-us,MSDN.10).png

  7. The Add New Project dialog box, configured to create a WF Task project named WeatherInformationTasks in the E:\Walkthroughs\WeatherInformation\WFTask folder

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

  9. In the Create New WF Task Project dialog box, in the Namespace box, type WeatherInformationNamespace, and then click Finish.

  10. The following image shows the Create New WF Task Project dialog box.

  11. Dd632063.900f7707-7604-4632-a7e6-fddc29703b5a(en-us,MSDN.10).png

  12. The Create New WF Task Project dialog box configured to create a new WF Project in the WeatherInformationNamespace namespace

To create a DCS Task that implements a stub operation definition.

  1. Right-click the WeatherInformationTasks project node, and then click Add WF Operation.

  2. In the Add New WF Operation dialog box on the Assembly or Project page, click the ellipsis button (…).

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

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

  5. Dd632063.d5d3f773-ddd5-4792-b724-5e4ccdca2e6f(en-us,MSDN.10).png

  6. The Assembly or Project page of the Add New WF Operation dialog box, configured to create a new WF operation implementation based on the E:\Walkthroughs\WeatherInformation\Stub\WeatherInformationStubs\bin\Debug\WeatherInformationStubs.dll assembly

  7. In the Add New WF Operation dialog box, click Next.

  8. On the Operation page, in the Select operation to implement list, click GetTemperature, and then click Next.

  9. The following image shows the Operation page.

  10. Dd632063.fe81dd3c-7462-40c5-82c2-33e9cce1f2b6(en-us,MSDN.10).png

  11. The Operation page of the Add New WF Operation dialog box, configured to implement the GetTemperature operation

  12. Note

    The Add New Operation dialog box does not request details of the message types to use in the task implementation. Message types are defined in the operation instead of in the task. Therefore, the message types are derived from the operation definition.

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

  14. The following image shows the WF Assemblies References Selector page.

  15. Dd632063.e8db0f33-2ce6-4881-bb18-ca0c76a5e6cf(en-us,MSDN.10).png

  16. The WF Assemblies References Selector page of the Add New WF Operation dialog box

To implement task functionality in a workflow

  1. In Solution Explorer, under WeatherInformationTasks 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.

  5. In 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 a SendResponse activity onto the designer surface, and drop it below the retrieveCityTemperature activity.

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

  11. 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.
  12. Your workflow should resemble the following image.

  13. Dd632063.7bd42dc1-8579-4c1c-9676-11f52ea6d4df(en-us,MSDN.10).png

  14. A WF Task sequential workflow containing a single CodeActivity activity, and a SendResponseActivity activity

Continue to implement tasks that appear in the Stubs project until you have implemented all the operations defined in the stub. After you finish, you can build the Tasks project and deploy the tasks.

To build and deploy tasks

  1. On the Build menu, click Build WeatherInformationTasks.
  2. In Solution Explorer, right-click the WeatherInformationTasks project in the Tasks folder, and the click Deploy Assembly. For more information, see Walkthrough: Deploying DCS Services by Using Visual Studio.

See Also

Walkthrough: Creating a DCS Solution

Walkthrough: Creating a DCS Messages Project

Walkthrough: Implementing a DCS Stub

Walkthrough: Deploying DCS Services by Using Visual Studio