I had a previous post (click here) about how to build a WCF queued messaging scenario. that example used self-hosted services. you can refer back to that post for all the details. in this post i will quickly show you how to get a WCF service with MSMQ binding hosted in IIS 7 up and running.
Create a simple WCF web site, and add a simple operation as follows:
below is the service configuration:
This is a WCF services hosted on IIS, listening to a MSMQ endpoint through the net.msmq binding. also I have exposed the mex http endpoint to enable adding a service reference from the client application.
next we need to enable the net.msmq binding on IIS 7 as its not enabled by default. on the web site hosting your service and on the service itself, go to configuration and add “net.msmq” to the list of bindings. by default it will only have “http”.
now lets turn our focus into MSMQ itself. turn on the MSMQ feature from the control panel. once you do you will be able to access it through right clicking on My Computer and clicking Manage. from there create a private queue called “TestWCFMSMQ/Service.svc” if you followed the same naming i used. else use “[yourvirtualdirectoryname]/[myservicefile].svc”. i will explain later why this naming convention is important.
next, give the application pool identity account sufficient priveleges on the queue created. this can simply be done by right click and properties on the queue itself.
final step is to make sure the windows service “Net.Msmq Listener Adapter” is running. this is the service that checks for new messages in queues and notifies the WCF service about them. now for some reason that at the time of this post i do not yet know, this service failed to notice the messages in the queue unless the queue name is in the format i created above…will post an update once i know what’s the catch here…
oh,one more thing: when creating the private queue make sure to make it Transactional.
now create a simple console application and add a service reference to the WCF service using the mex http endpoint. use the below code to invoke the service operation:
to see queuing in action. from IIS stop the WCF service. now run the client which drops a message in the private queue. open the queue and notice the message. now from IIS run the WCF application, wait for a couple of seconds and the message will be delivered to the service and disappear from the queue.