Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Create a Durable and Reliable WCF Service with MSMQ 4.0 : Page 2

Developers have to ensure that their Windows Communication Foundation (WCF) endpoints are durable and reliable, because transactions depend on them. Learn how to bullet proof your WCF services with MSMQ 4.0.


advertisement
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.

Click to enlarge

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).

Click to enlarge

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.

Click to enlarge

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.

Click to enlarge

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"); Console.WriteLine(order.StringValue); } #endregion }

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:

<client> <endpoint address="net.msmq://localhost/private/OrderQueue" binding="netMsmqBinding" bindingConfiguration="" contract="OrderService.IOrderService" name="OrderService"> </endpoint> </client>

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.



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date