Share via


Buffered Receive

This topic applies to Windows Workflow Foundation 4 (WF4).

This sample demonstrates how to set up and configure the buffered receive feature in Windows Workflow Foundation (WF). Buffered receive allows the workflow author to create a workflow without having to worry about the order in which messages are received. The buffered receive feature buffers messages locally and delivers them when the workflow is ready to receive them.

Demonstrates

Out-of-order message processing using buffered receive with messaging activities.

Discussion

In this sample, a Windows Communication Foundation (WCF) service is implemented using WF and has a sequence of Receive activities. This workflow models a simple loan approval process where the workflow expects three notifications for a loan to be approved. A Windows Communication Foundation (WCF) client application sends three correlated notifications in the reverse order of what the service expects. Because the buffered receive feature is turned on at the service, each out-of-order message is buffered at the service and processed as the workflow becomes ready to receive it.

The buffered receive feature requires ReceiveContent support from the binding, therefore the service uses NetMsmqBinding. No special configuration is required for the binding, so the defaults are used.

<endpoint address ="net.msmq://localhost/private/LoanService/Service1.xamlx"
                  binding="netMsmqBinding"
                  contract="ILoanService"/>

The service also exposes metadata for the service using ServiceMetadataBehavior.

Similarly, the client endpoint is configured using NetMsmqBinding. The client code and configuration is generated by using the Add Service Reference feature of Visual Studio. The following example is the generated client endpoint in the App.config file.

<endpoint address="net.msmq://localhost/private/LoanService/Service1.xamlx"
                binding="netMsmqBinding" bindingConfiguration="NetMsmqBinding_ILoanService"
                contract="ServiceReference1.ILoanService" name="NetMsmqBinding_ILoanService" />

This sample requires that the following Windows components are enabled:

  1. Internet Information Services (IIS) 6.0

  2. Internet Information Services (IIS) 6.0 Management Compatibility, Metabase, and Configuration Compatibility

  3. World Wide Web Services, Application Development Features, and ASP.NET

  4. Microsoft Message Queues (MSMQ) Server

To set up, and build the sample

  1. At a Visual Studio 2010 command prompt, register ASP.NET by typing aspnet_regiis –I and press ENTER.

  2. Run Visual Studio 2010 as an Administrator.

  3. Open LoanService.sln.

  4. When asked if you would like to create the virtual directories for the LoanService project, select Yes.

To set up the service queues

  1. Press F5 to run the LoanClient application that creates the queues and activates the service defined in Service1.xamlx.

  2. Open the Computer Management console by running Compmgmt.msc from a command prompt.

  3. In the Computer Management console, expand Service, Applications, Message Queuing, Private Queues.

  4. Right-click the loanservice/service1.xamlx queue and select Properties.

  5. Select the Security tab, and add Everyone Receives Message, Peek Message and Send Message permissions.

  6. Open the Internet Information Services (IIS) 6.0 Manager.

  7. Browse to Server, Sites, Default Web site, Private, LoanService and select Advanced Options

  8. Change the Enabled Protocols to be http, net.msmq.

To run the sample

  1. Browse to https://localhost/private/loanservice/service1.xamlx to ensure that the service is running.

  2. Press F5 to run the LoanClient application. Once the workflow is complete, an out.txt file should be saved to C:\Inbox that contains the result of the message exchange.

To clean up

  1. Open the Computer Management console by running Compmgmt.msc from a command prompt.

  2. Expand Service and Applications, Message Queuing, Private Queues.

  3. Delete the loanservice/service1.xamlx queue.

  4. Remove the C:\Inbox directory.

Ee834509.Important(en-us,VS.100).gif Note:
The samples may already be installed on your computer. Check for the following (default) directory before continuing.

<InstallDrive>:\WF_WCF_Samples

If this directory does not exist, go to Windows Communication Foundation (WCF) and Windows Workflow Foundation (WF) Samples for .NET Framework 4 to download all Windows Communication Foundation (WCF) and WF samples. This sample is located in the following directory.

<InstallDrive>:\WF_WCF_Samples\WF\Basic\Services\BufferedReceive