While Activity
Introduction
This sample demonstrates the use of the while activity. In this example, a while activity is used to loop through a sequence of order detail records and calculate the total cost of all of the items in the order. The process consists of:
- A receive/reply pair that accepts the order and returns a response.
- Variables that hold the order detail index, total cost, and other values.
- A while activity that uses those variables to loop through the sequence of order detail records and calculate the total cost.
The diagram below is a visual representation of the process. The
process is
instantiated when an order message is received. The first assign
initializes
the number of detail records by using the count() XPath
expression, sets the detail index to 1 (XPath arrays are 1-based), and
sets
the total amount to zero.
The while activity's condition compares the index to the number of order detail records. As long as the index is less than or equal to the number of records, the while activity will execute. Inside the while activity is a sequence containing two assign activities. The first assign adds (item count * item cost) to the order total. The second increments the index.
When the while activity is finished (the index is greater than the number of order detail records), the process continues by executing the assign activity that creates the response message and then replying with the answer.
Deploying the Process
Running the Process
See Running the Samples.
The
service name to use is whileProcessService. The sample data file
orderMessage.xml can be used as input for this example.
Copyright © 2004–2007 Active Endpoints, Inc.
