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
In the DCS solution, right-click the WFTask folder, point to Add, and then click WF Task.
In the Add New Project dialog box, in the Templates list, click WF Task.
In the Name box, type WeatherInformationTasks, and then click Browse.
In the Project Location dialog box, browse to the E:\Walkthroughs\WeatherInformation\WFTask folder, and then click OK.
The following image shows the Add New Project dialog box.
The Add New Project dialog box, configured to create a WF Task project named WeatherInformationTasks in the E:\Walkthroughs\WeatherInformation\WFTask folder
In the Add New Project dialog box, click OK.
In the Create New WF Task Project dialog box, in the Namespace box, type WeatherInformationNamespace, and then click Finish.
The following image shows the Create New WF Task Project dialog box.
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.
Right-click the WeatherInformationTasks project node, and then click Add WF Operation.
In the Add New WF Operation dialog box on the Assembly or Project page, click the ellipsis button (…).
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.
The following image shows the Assembly or Project page.
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
In the Add New WF Operation dialog box, click Next.
On the Operation page, in the Select operation to implement list, click GetTemperature, and then click Next.
The following image shows the Operation page.
The Operation page of the Add New WF Operation dialog box, configured to implement the GetTemperature operation
-
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.
On the WF Assembly References Selector page, click Finish.
The following image shows the WF Assemblies References Selector page.
The WF Assemblies References Selector page of the Add New WF Operation dialog box
To implement task functionality in a workflow
In Solution Explorer, under WeatherInformationTasks in the GetTemperature folder, right-click the GetTemperatureWorkflow.cs file, and then click View Designer.
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.
Change the activity (Name) property to retrieveCityTemperature, and then double-click the activity to create an event handler.
Visual Studio opens the GetTemperatureWorkflow.cs code-behind file, and creates a new event handler method.
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.
Your code should resemble the following example.
-
private void retrieveCityTemperature_ExecuteCode(object sender, EventArgs e) { this.Response.Temperature = 23; }
Switch back to the workflow designer
From the toolbox in the DCS tool group, drag a SendResponse activity onto the designer surface, and drop it below the retrieveCityTemperature activity.
Change the activity (Name) property to sendResponse.
Bind the activity Response property to the workflow Response property:
-
- Click the Response property, and then click the ellipsis button (…) that appears.
- In the Bind 'Response'to an activity's property dialog box, on the Bindto an existing member tab, click Response, and then click OK.
Your workflow should resemble the following image.
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
- On the Build menu, click Build WeatherInformationTasks.
- 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