Delen via


Host Communication Sample

Download sample

This sample demonstrates how to communicate with the workflow host application by using a local service interface.

For the host application to communicate with a running workflow, a local service class must be used. The local service class implements methods that can be called by the host application, and events that the workflow can listen for by using HandleExternalEventActivity activities. An ExternalDataExchangeService service is added to the workflow runtime using AddService; the local service class is then added to the External Data Exchange service. The workflow then accesses the local service by querying for an interface that the local service class implements.

In the sample, an instance of the service class VotingService is added to the runtime. The workflow then interacts with this service by querying for an object that implements the IVotingService interface.

The voting service class and interface support two events: ApprovedProposal and RejectedProposal. The host application raises these events via the CreateBallot method; the events are then handled in the workflow via HandleExternalEventActivity activities (from a ListenActivity activity).

To build the sample

  1. Download the sample by clicking Download Sample.

    This extracts the sample project to your local hard disk.

  2. Click Start, point to Programs, point to Microsoft Windows SDK, and then click CMD Shell.

  3. Go to the source directory of the sample.

  4. At the command prompt, type MSBUILD <Solution file name>.

To run the sample

  1. In the SDK Command Prompt window, run the .exe file in the HostCommunication\bin\debug folder (or the HostCommunication\bin folder for the Visual Basic version of the sample), which is located below the main folder for the sample.

See Also

Reference

HandleExternalEventActivity
ListenActivity

Other Resources

Using the HandleExternalEventActivity Activity
Creating Custom Communication Activities
Communicating with Other Workflows
Using the ListenActivity Activity
Activities Samples
Communications Samples
Windows Workflow Foundation Samples

© 2007 Microsoft Corporation. All rights reserved.