Two new activities are available with .NET 3.5 that support integration between workflows and WCE. These are the Send Activity and the Receive Activity. The Send Activity could more aptly be called the Call Activity, because what it does is issue a request to a WCF service and can optionally surface the results as parameters that can be bound to within the calling workflow.
Somewhat more interesting, however, is the new Receive Activity. This allows a workflow to become the implementation of a WCF service, so now the workflow is the service. The following example exposes a service using a workflow and also uses the new service test host tool to test the service without having to write a separate test harness.
Fro~ the New Project menu in Visual Studio 2008, choose the WCF node and then the Sequential Workflow Service Library entry as shown in Figure 43-21.
This will create a library that contains a workflow as shown in Figure 43-22,an application configuration file, and a service interface.
The workflow exposes the Hello operation of the contract and also defines properties for the arguments passed to this operation, and the return value of the operation. Then, all you need to do is to add code that provides the execution behavior of the service, and your service is complete,
To do this for the example, drag a Code Activity onto the Receive Activity as shown in Fig 43-23, and then double-click that activity to supply the service implementation.
Because the service contract for the Hello operation includes both a parameter (inputMessage) and a return value, these have been exposed to the workflow as public fields. Within the code, we have set the return Value to a string value, and this is what is returned from a call to the WCF service.
If you compile this service and hit FS, you will notice another new feature of Visual Studio 2008- the WCF Test Client Data application, as shown in Figure 43-24.
Here you can browse for the operations that the service exposes, and by double-clicking an operation, the right-hand side of the window is displayed, which lists the parameters used by that service and any return value(s) exposed.
To test the service, enter a value for the message property and click the Invoke button. This will then make a request over WCF to the service, which will construct and execute the workflow, call the code
activity, which then runs the code-behind,,and ultimately return to the WCF Test Client the result from the workflow.
If you wish to manually host workflows as services, you can use the new Workflow Service Host class defined within the System. syustem.workflowServices assembly. The following snippet shows a minimal host implementation:
Here we have constructed an instance of Workflow Service Host and passed it the workflow that will be executed. This is similar to how you would use the Service Host class when hosting WCF services. It will read the configuration file to determine which endpoints the service will listen on and then a wait service requests.
The next section describes some other options you have for hosting workflows.