Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
In this task, you define the IOrderingService interface and a class that is used to pass data from the host application to the state machine workflow when a new order is submitted.
The IOrderingService interface is used to make communication easier between the Simple Order Form host application and the OrderProcessingWorkflow.
The interface contains a single method and a defined event:
The
ItemStatusUpdatemethod is used by theOrderProcessingWorkflowto send status updates back to the host application.The
NewOrderevent is the initial event that starts theWaitingForOrderstate activity. It is raised by the Simple Order Form host application whenever the user submits a new order.
Note
Although you are encouraged to follow the exercises in a linear manner, it is not required. You can start this exercise by opening the sample project and proceeding to the steps in the following section.
Defining the NewOrderEventArgs Class
First, you must define the class that is used to pass data from the host application to the state machine workflow when an order is submitted. This class derives from ExternalDataEventArgs, the base class for data objects that store data contained in events raised by the host.
To define the NewOrderEventArgs class
In the StateMachineWorkflow project, create a new class file named NewOrderEventArgs.cs. Make the class
public, and addExternalDataEventArgsas the base class for this new class. Add a reference toSystem.Workflow.Activitiesto the declarations in the file using the Options menu available on the class name.Make the class serializable by applying the SerializableAttribute attribute.
<Serializable()> _ Public Class NewOrderEventArgs : Inherits ExternalDataEventArgs End Class[Serializable] public class NewOrderEventArgs : ExternalDataEventArgs { }In the
NewOrderEventArgsclass, declare the fields in the following table.Access ModifierTypeNamePrivateSystem.GuidorderItemIdPrivateSystem.StringorderItemPrivateSystem.Int32orderQuantityprivate Guid orderItemId; private string orderItem; private int orderQuantity;Create a public constructor for the
NewOrderEventArgsclass that takes the following as parameters:These parameters contain the workflow ID of the destination workflow, a string that defines the name of an item, and an integer value that defines an item quantity. In the body of the constructor, assign each field that you created in the previous step with the associated parameter passed into the constructor. This stores the data provided when the constructor is called.
public NewOrderEventArgs(Guid itemId, string item, int quantity) : base(itemId) { this.orderItemId = itemId; this.orderItem = item; this.orderQuantity = quantity; }In the
NewOrderEventArgsclass, create a public System.Guid property namedItemId.Create a
getmethod for this property and return the value of theorderItemIdfield, and asetmethod that sets theorderItemIdfield.public Guid ItemId { get { return orderItemId; } set { orderItemId = value; } }In the
NewOrderEventArgsclass, create a public System.String property namedItem.Create a
getmethod for this property and return the value of theorderItemfield, and asetmethod that sets theorderItemfield.public string Item { get { return orderItem; } set { orderItem = value; } }In the
NewOrderEventArgsclass, create a public System.Int32 property namedQuantity.Create a
getmethod for this property and return the value of theorderQuantityfield, and asetmethod that sets theorderQuantityfield.public int Quantity { get { return orderQuantity; } set { orderQuantity = value; } }
Creating the Interface
Next, you define the IOrderingService interface. This is used for communication between the workflow and the host application. The workflow contains an activity that listens for events using this interface. The host sends messages to the workflow using a service that implements this interface.
To define the IOrderingService interface
In the StateMachineWorkflow project, create a new class file named
IOrderingService.cs. Make the interfacepublic.Add a
usingstatement for theSystem.Workflow.Activitiesnamespace.Imports System.Workflow.Activitiesusing System.Workflow.Activities;Because this interface is used for communication between the host application and the
OrderProcessingWorkflow, apply the ExternalDataExchangeAttribute attribute. This attribute identifies the interface as a local service interface.<ExternalDataExchange()> _ Public Interface IOrderingService End Interface[ExternalDataExchange] public interface IOrderingService { }In the
IOrderingServiceinterface, create a method namedItemStatusUpdatethat takes the following as parameters:A Guid named
orderId.A String named
newStatus.
void ItemStatusUpdate(Guid orderId, string newStatus);In the
IOrderingServiceinterface, create a new event namedNewOrderwhose type is a genericEventHandlerof theNewOrderEventArgstype.event EventHandler<NewOrderEventArgs> NewOrder;
Compiling the Code
For more information about compiling your code, see Compiling the Code.
In the next task, Task 3: Implement the IOrderingService Interface, you implement this interface in the Simple Order Form host application.
See Also
Reference
Concepts
Windows Workflow Foundation and Application Communication
State Machine Workflows
Other Resources
Task 3: Implement the IOrderingService Interface
Tutorial: Create a State Machine Workflow
Communications
Host Communication Sample
Ordering State Machine
Simple State Machine
Copyright © 2007 by Microsoft Corporation. All rights reserved.
Last Published: 2010-03-04