Guaranteed, Durable Delivery in WCF
The only way to ensure guaranteed, durable delivery in WCF is by using the NetMsmqBinding on a Windows 2008 clustered server. WCF does have Web Services Reliable Messaging (WSRM) support, but the WSRM specification leaves a lot of open-ended questions. Hence, WCF support for WSRM is fairly negligible.
Figure 1 shows the details of the order-processing service that will be presented in the rest of this article. At the core is the OrderService, a WCF service that is exposed as a Net MSMQ endpoint.
| Figure 1. Details of the Order-Processing Service:|
Here are the details of the order-processing service that will be presented in the rest of this article.
This section walks through building the central piece of the order-processing service, OrderService (see Figure 2).
|Figure 2. Building the Core Service:|
The central piece of the order-processing service is OrderService.
The service contract shown in Listing 1 contains a method called ProcessOrder. Because this contract is exposed as a NetMSMQBinding, it supports methods that return only a void type (OneWay). If a service needs to support other methods that require a response to be sent, those methods are best suited for a different endpoint with a new service contract.
Figure 3 shows the details of the configuration that will allow the OrderService endpoint to be reachable.
|Figure 3. Service Configuration Details:|
Here are the details of the configuration that will allow the OrderService endpoint to be reachable.
A Net MSMQ endpoint has an Address that starts with a net.Msmq and then has a /private/OrderQueue, which represents the private queue that you will have to create and make transactional (see Figure 4). If you do not have MSMQ, it is a standard install in the Windows operating system that you can add.
|Figure 4. Create Private Queue and Make Transactional:|
A Net MSMQ endpoint has an Address that starts with a net.Msmq and then has a /private/OrderQueue.
At this point you have created a queue that will be on the same server as the machine on which the WCF service is running, and the WCF service is not pointing to a queue on the Windows cluster. The queue needs to be transactional to enable durable messaging. The following listing shows the service implementation to make this happen:
[ServiceBehavior(ConfigurationName = "OrderProcessingService")]
public class OrderService : IOrderService
#region IOrderService Members
public void ProcessOrder(Order order)
Console.WriteLine("recieved the order\n");
If the client is a .NET 3.5 application, then the consumption is easy. Simply add a section in the client code as shown in the following listing:
<endpoint address="net.msmq://localhost/private/OrderQueue" binding="netMsmqBinding"
Note that the address is pointing to a private queue on the local machine.
The service is now ready to be consumed. In the example included in the code download, just open the Visual Studio solution called OrderService. Make sure the client and the host are set as startup projects. If you run this, you should see a message sent from the client and received on the server side.
Now you are ready to set up the Windows 2008 cluster.