Search Wiki:

Description


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.

DemoScreenShot-High.jpg

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:
  1. Get the feel for an existing System.Messaging (MSMQ) demo application
  2. Implement the equivalent application using WCF Queuing (MSMQ + WCF)
  3. Integrate a prototype MSMQ chunking channel into the application enabling us to send messages > 4mb in size over MSMQ
  4. Use the MSMQ Integration binding to send messages from the original System.Messaging sender to a new WCF receiver for processing

There are a couple ways you can walk-thru this sample:

  • Watch a Video
  • Read a Doc (PDF)
    • 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.

Prereqs


Before we get started, you’ll need to ensure your machine has the following:

  1. .Net framework 3.0 or greater (http://msdn2.microsoft.com/en-us/netframework/aa569263.aspx)
  2. MSMQ Installed (http://msdn2.microsoft.com/en-us/library/aa967729.aspx)
  3. Visual Studio 2005 or greater (http://www.microsoft.com/express/)
  4. The sample solution for this walk-thru

Good luck and happy SOA'ng!

About the Author

Justin Wilcox is the former test lead of Microsoft Message Queuing (MSMQ), System.Messaging, and WCF Queuing contributing to releases from '03 to '08.
Last edited Feb 4 2008 at 11:35 AM  by JustinWi, version 20
Comments
simoneb wrote  Feb 2 2008 at 4:30 AM  
Great sample, thanks.

monty wrote  Feb 5 2008 at 5:35 AM  
Justin ,

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.

WenWu wrote  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!

JustinWi wrote  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.

Justin

sb wrote  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...

JoshW wrote  Mar 24 2008 at 3:54 PM  
Hi Justin,

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.

Marky wrote  May 10 2008 at 5:44 AM  
Hi Justin,
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?

ChristianWeyer wrote  May 16 2008 at 11:51 PM  
Justin,

nice :)
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 :(

Thx,
-Christian

CosineKitty wrote  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.
Thanks,
Don

Raag wrote  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.

Raag wrote  Jul 11 2008 at 3:51 PM  
Hi Don,
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......?

any idea...?

Cathal wrote  Jul 28 2008 at 3:16 PM  
Question:
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.

Thanks,
Cathal.

Cathal wrote  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:
http://msdn.microsoft.com/en-us/library/ms789048.aspx
http://blogs.msdn.com/tomholl/archive/2008/07/14/msmq-wcf-and-iis-getting-them-to-play-nice-part-3.aspx
http://msdn.microsoft.com/en-us/library/ms731093.aspx

JoeAbr wrote  Aug 7 2008 at 6:18 AM  
Hi,
Does this work over MSMQ 3.0? If no, is there a way to acheive chunking in MSMQ 3.0 using WCF channel?

Thanks,
Joe

rahulsharma347 wrote  Feb 19 2009 at 10:25 AM  
Hi,

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.

Thanks,
Rahul

sleepwaking wrote  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?

Will

dragoshaiduc wrote  Oct 13 2009 at 1:25 PM  
See discussions and issue tracker.

Gravitas wrote  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.

sixmileal wrote  May 8 2011 at 1:54 AM  
Justin,
Quick question. For WCF MQ, besides the 4MB message limitation, is the queue size only limited by system resources (RAM/disk)?
Thanks,
Al

rk_muddala wrote  Mar 1 2012 at 6:31 AM  
Thanks a ton :-).Nice article with simple steps to being with...

Updating...
Page view tracker