MSDN Archive Home
Help and FAQs
SOA'izing MSMQ with WCF (and Why It's Worth It)
All Resource Updates
Change History (all pages)
Microsoft Message Queuing’s (MSMQ) integration with the Windows Communication Foundation (WCF) is extremely powerful. It enables MSMQ developers to write fault-tolerant, service-oriented applications and provides a robust extensibility model developers can use to improve any system’s capabilities – including MSMQ’s. In this video and corresponding sample we'll convert a System.Messaging application into a WCF Queuing application, enable that application to overcome MSMQ’s 4mb message size limitation with a prototype chunking channel, and integrate it seamlessly with existing MSMQ applications.
Why SOA'ize MSMQ with WCF
Microsoft Message Queuing (MSMQ) is an incredibly robust, time-tested messaging server that fulfills a critical role in any communications platform. What it doesn’t do however, is play well in a service oriented world. MSMQ applications and their developers must be fully aware of the queue’s they’re communicating with and hand-craft messages to be sent on the wire. In a Service Oriented Architecture (SOA) world, we don’t think in terms of message in queues, we think in terms of business operations allowing developers to focus on what’s most important…business operations. Centering application development around these operations enables us to be flexible with not only with our implementations, but also our communication partners. In addition, the extensibility mechanisms provided when we integrate MSMQ with Windows Communication Foundation (WCF) are extremely powerful and enable MSMQ developers to do things they never could before.
What We'll Cover
Combining the power of MSMQ with the flexibility of WCF, we'll do the following:
Get the feel for an existing System.Messaging (MSMQ) demo application
Implement the equivalent application using WCF Queuing (MSMQ + WCF)
Integrate a prototype MSMQ chunking channel into the application enabling us to send messages
in size over MSMQ
Use the MSMQ Integration binding to send messages from the original System.Messaging sender to a new WCF receiver for processing
There are also two ways you can walk-thru this sample:
Note: copying & pasting code from the PDF doesn't work as well as from the doc file.
Once you've met the prereqs. below, select either of these to get started.
Before we get started, you’ll need to ensure your machine has the following:
.Net framework 3.0 or greater (
MSMQ Installed (
Visual Studio 2005 or greater (
for this walk-thru
Good luck and happy SOA'ng!
Jan 31 2008 at 3:34 AM
, version 11
Feb 2 2008 at 4:30 AM
Great sample, thanks.
Feb 5 2008 at 5:35 AM
Great Article . Have a question for u .
We have a application written in Powerbuilder and one in Java.
What are the requirements for them to communicate with MSMQ with WCF.
Feb 5 2008 at 10:55 AM
Nice sample! Got a question, how to authenticate server and client and encrypt the messages over the internet without active directory using WCF end points with MSMQ binding? Thanks!
Feb 8 2008 at 11:23 AM
Thanks for the feedback and questions, much appreciated.
Monty, unfortunately I don't have much experience with PowerBuilder but unless you're able to leverage .Net 3.0 functionality with it, I'm not sure how it would intergrate with WCF. Same goes with Java. If you want to leverage WCF + MSMQ, you'll need to look into .Net.
Wen, unfortunately w/o AD, you can only acheive authentication using an external certificate. You can however encrypt the data yourself before sending it. Check out http://msdn2.microsoft.com/en-us/library/ms789030.aspx for more information.
Feb 18 2008 at 2:26 PM
Hello, That's interesting, but since I started learning WCF I've been making the assumption that you can only use MSMQ with WCF in enterprise apps that live *within* the corporate firewall. And that you could never use MSMQ for an external-facing SOA app that other clients could access over the internet.
Am I wrong (I hope so!). If not, then this severly limits the use of using MSMQ with WCF in SOA apps...
Mar 24 2008 at 3:54 PM
Great tutorial. I started WCF programming last week and the tutorial is very clear on how to get started.
Is the ChunkingChannel beta source code released yet? I looked through the tutorial VS solution as well as the MSMQ blog and haven't found it.
May 10 2008 at 5:44 AM
This is just the stuff i need to learn and apply. Sadly, I cant get the demo code to work with Vista ultimate. The message queue does not get created. The netsh add http... command throws a parameter incorrect error. Any ideas how to get this to work with Vista?
May 16 2008 at 11:51 PM
But to be really usefull it would be cool if you could support [MessageContract] - with Stream as the bidy and additional (and needed) data carried in headers, like name of the file and more stuff.
Otherwise it is less useful :(
Jun 10 2008 at 6:06 PM
Hi Justin, I am having the same problem (I think) as Marky. When I try to run the netsh command, I see:
The following command was not found: http add urlacl url=http://+:80/ user=DOMAIN\user
(I have replaced my actual domain and user with "DOMAIN\user" above, but I did have it correctly entered.)
And then when I try to run Server and click the "Start Watching" button, I get an exception that says:
"The queue does not exist or you do not have sufficient permissions to perform the operation."
I am new to MSMQ and WCF programming, and any help you could provide would be greatly appreciated.
Jul 11 2008 at 3:33 PM
I have also got the same Error as don mention in above comments....tried to search for the same but couldnt get any result.
Jul 11 2008 at 3:51 PM
I have created a private Queue named 'MSMQORDERS" and given access to everyone. this has solved one of the problem that is "The queue does not exist or you do not have sufficient permissions to perform the operation."
but the error now is
HTTP could not register URL http://+:80/HTTPOrderService.svc/ because TCP port 80 is being used by another application......?
Jul 28 2008 at 3:16 PM
The WCF/MSMQ solution hides a lot of the boiler-plate code in setting up the MSMQ logic. This is great, but how can I successfully receive a message on the server app, but DO NOT remove it from the queue until I say so. e.g. after receiving the message I try to communicate with a 3rd party web service - if something goes wrong here, then the message will stay in the queue, and we will retry again later.
Jul 29 2008 at 2:41 PM
A couple of links I stumbled across that might be useful for implementing MSMQ transaction support over WCF:
Aug 7 2008 at 6:18 AM
Does this work over MSMQ 3.0? If no, is there a way to acheive chunking in MSMQ 3.0 using WCF channel?
Feb 19 2009 at 10:25 AM
I am running code as written in section "Overcoming MSMQ’s 4mb Message Size Limitation" but it gives me error "Transaction.Current has changed inside Transaction scope:InvalidOperationException". Tried to search for the same but couldnt get any result. Could you please help me out.
Jul 13 2009 at 10:10 PM
Great sample. I too ran into the issue requiring the queues to be created, no problem. And then the issue mentioned by "Raag" above about not being able to register URL . . . I simply changed the code that build the service Uri to append a port (89 in my case) so it wouldn't collide with my IIS server runing on port 80.
And now, I am having the same issue as "rahulsharma347" where the chunking piece doesn't work and throws the "Transaction.Current has changed inside Transaction scope" . . . anyone solve that yet?
Oct 13 2009 at 1:25 PM
See discussions and issue tracker.
Oct 15 2010 at 3:48 PM
Fantastic article - its great to know that with WCF, you can just change the transport layer to get all the advantages that MSMQ offers.
May 8 2011 at 1:54 AM
Quick question. For WCF MQ, besides the 4MB message limitation, is the queue size only limited by system resources (RAM/disk)?
Mar 1 2012 at 6:31 AM
Thanks a ton :-).Nice article with simple steps to being with...
Sign in to add a comment
MSMQ + WCF Integration...
Mon Jan 28 2008 at 8:00 AM
More Tags ...
Visual Studio 2005
Visual Studio 2008
Visual Studio 2010
Manage Your Profile
MSDN Flash Newsletter
© 2008 Microsoft Corporation. All rights reserved.