Beruflich Dokumente
Kultur Dokumente
Summary: This article describes how to set up MSMQ activation for WCF Workflow Service Application
hosted in Windows Activation Service (WAS). This page is specific to
Microsoft Visual Studio
2008/.NET Framework 4
Introduction Beta 2.
In .NET Framework 4 and Visual Studio 2010, you can build pure Windows Communication Foundation
(WCF) services, pure Workflow Foundation (WF) applications, or a workflow service, which is a workflow
application exposed as a WCF service. The out-of-box messaging activities, e.g. Send and Receive
activities, come with implicit WCF endpoints, which can be employed for external communication to the
workflow, including WCF activation of the workflow instance when the first message arrives.
A workflow service, like any application with a communication component, can benefit from the
advantages of queuing technologies. Adding a queue element to application design can improve
robustness. The queue can also provide load-balancing support and improve scalability.
Microsoft Messaging Queue (MSMQ) provides easy-to-use, high throughput message queuing
capabilities that send and receive messages between applications that run on separate servers or
processes. MSMQ implements a queue, which acts as a temporary storage for messages to go through.
Due to the nature of its design, the canonical scenario for MSMQ is the asynchronous messaging pattern.
For example, the recipient of the message becomes unavailable, due to a technical issue or during
scheduled off hours, the incoming messages will be stored in the in-memory queue on the MSMQ server.
Once the recipient becomes available, the messages will be sent to the recipient from the queue in the
FIFO order or priority-based order. This enables reliable communication between heterogeneous
networks and between computers that may not always be connected.
MSMQ by default stores messages in memory, thus, it provides near real-time message exchange
throughput. The server can crash and messages can be lost, therefore the default setting is good for
scenarios that do not need guarantee of reliability. You can choose to store messages on disk by turning
on recoverable messaging. This gives you improved reliability, in exchange of performance.
MSMQ also supports transactions, either internal transactions using MessageQueueTransaction class, or
external transactions with Distributed Transaction Coordinator (DTC). This ensures that messages are
received exactly once, in order. If there is an error occurred, the transaction scope is rolled back.
Transactional queues are slower due to the transaction design and disk-access for queues.
In this article, for simplicity, we will use non-transactional in-memory MSMQ to enable reliable
asynchronous communication for a .NET 4 workflow service.
Prerequisites
Before you go through the following example, please check the following prerequisites.
- Microsoft Visual Studio 2010 (Beta 2) - Download
- Microsoft .NET Framework 4 (Beta 2) - Download
- Windows Features
o IIS 7.0/WAS enabled (http://learn.iis.net/page.aspx/29/installing-iis-70-on-windows-
server-2008/)
o MSMQ installed (http://msdn2.microsoft.com/en-us/library/aa967729.aspx)
- Windows Services
o Net.Msmq Listener Adapter service started
The screenshots of this article are taken from Windows 7 Enterprise environment.
Step-by-Step Instructions
2. By default, the template creates a Sequential Service, which contains a pair of Receive and Send
activities called ReceiveRequest and SendResponse. This is a .NET 4 workflow service, which
contains a workflow with activities, some of which may be messaging activities with implicit
WCF endpoints for communicating with other services or applications.
Default .NET 4 Workflow Service
3. Modify the workflow service so that it implements a one-way communication pattern, by using
a Receive activity only instead of the default request/response two-way communication.
a. Open the service file named Service1.xamlx and remove the Send activity named
SendResponse. Save the project.
After the SendResponse activity is removed, the workflow service has one activity
ReceiveRequest wrapped in the Sequential Service.
4. Change the project Web settings to Local IIS Web Server to enable WAS hosting for the new
service
a. Right click on the project and select Properties
b. In Web tab, select the radio button for Use Local IIS Web Server.
Toggle from Visual Studio Development Server to Local IIS Web server
b. MSMQ supports transactional messaging scenarios. To keep this example simple, the
scenario is non-transactional, so leave the Transactional checkbox empty.
c. Click OK to create the queue. Expand Private Queue to confirm the new queue is
created.
New queue is created with two sub branches: Queue messages and Journal messages.
<system.serviceModel>
<services>
<service name="Service1" >
<endpoint
address="net.msmq://localhost/private/MyWFService/Service1.xamlx"
binding="netMsmqBinding"
bindingConfiguration=MyNetMsmqBinding
contract="IService"/>
<endpoint
address=""
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
<bindings>
<netMsmqBinding>
<binding name=MyNetMsmqBinding exactlyOnce=false>
<security mode=None/>
</binding>
</netMsmqBinding>
</bindings>
<behaviors>
c. Please note that the service has two endpoints, one is mex endpoint, the other is msmq
endpoint. Through the web browser, the service exposes metadata via mex endpoint.
This page indicates that the service is up and running.
WCF Test Client is used to test the activation of the workflow service. Note that the
service contract indicates NetMsmqBinding.
d. Click Invoke to send the message
e. In Server Manager, locate the queue MyWFService/Service1.xamlx and expand it to
find Journal messages. Double click on Journal messages, you should see one
message.
Reference
Queuing in WCF an MSDN article describing how to use queued communication in WCF 3.5.
MSMQ Activation an MSDN article with sample demonstrating a two-way communication scenario
with WCF 3.5 and MSMQ.