Visual Studio 2008: Windows Workflow Foundation
Visual Studio 2008: Windows Workflow Foundation
Visual Studio 2008: Windows Workflow Foundation
Windows® Workflow
Foundation
Module 3: Communicating with Workflows
• Calling Methods on the Host Process
Host Application
Workflow Runtime
ExternalDataExchangeService
Workflow Instance
CallExternal
MethodActivity
How to Call Methods on the Host Process
To make host process methods available to workflows:
• Define an interface that specifies available methods
• Specify the ExternalDataExchange attribute on the interface
• Define a service class that implements the interface
• Register a service class instance with the workflow runtime
Host Application
• TODO: Redraw the right-hand
Workflow Runtime
side of this diagram, to show
event handling ExternalDataExchangeService
Workflow Instance
Listen Activity
EventDrivenActivity
HandleExternal
EventActivity
Raising Events in the Host Process
To make host process events available to workflows:
• Define an interface that specifies events
• Specify the ExternalDataExchange attribute on the interface
• Define a service class that implements the interface and
raises events
• Register a service class instance with the workflow runtime
Generated
proxy
Defining a WCF Service
Create a WCF Service Library and define a WCF service as
follows:
• Define a service interface and annotate with ServiceContract
• Annotate the interface methods with OperationContract
• Annotate parameter and return data types with DataContract
• Define a class that implements the service interface
[ServiceContract]
public interface IProductsService
{
[OperationContract]
ProductInfo GetProduct(int ID);
} [DataContract]
public class ProductInfo
{
public class ProductsService : [DataMember]
IProductsService public string Name...
{...}
Invoking a WCF Service from a Workflow
To invoke a WCF service from a workflow:
• Add a reference to the WCF service in the workflow project
• Add a SendActivity to the workflow
• Set the ServiceOperationInfo property to an operation on
the WCF service
• Create a ChannelToken to specify the endpoint and owner activity
Binding Input and Output Parameters
To bind input and output
properties to a
SendActivity:
• Configure the
ServiceOperationInfo
property
• Visual Studio adds
required properties to
the SendActivity
Properties list
• Click a property, and
then right-click the
activity to display the
binding wizard
• Select the locally
available property from
the list
Demonstration: Consuming Services from
a Workflow
In this demonstration, you will see how to:
• Define a WCF service containing a method that takes
parameters and returns a value
• Add a SendActivity to a workflow to consume a service
method
Notes Page Over-flow Slide. Do Not Print Slide.
See Notes pane.
Lesson: Publishing a Workflow as a Service
• Why Publish a Workflow as a Service?
Client Workflow
application published as a
WCF Service
Generated
proxy
Defining a Service Contract
Create a class library and define a WCF service as follows:
• Define a service interface and annotate with ServiceContract
• Annotate the interface methods with OperationContract
• Annotate parameter and return data types with DataContract
[ServiceContract]
public interface IBasketService
{
[OperationContract]
void ProcessBasket(Basket b);
}
[DataContract]
public class Basket
{
[DataMember]
public int NumItems...
Associating an Activity with a Service Contract
To associate an activity with a service contract:
• Add a reference to the class library
• Add a ReceiveActivity to a workflow
• Set the ServiceOperationInfo property to an operation on
the service
• Bind input and output parameters to fields in the workflow
Implementing Service Behavior in an Activity
To implement service behavior
in an activity
Logon information
Password Pa$$w0rd
• Best Practices
• Tools