WCF NetMSMQBinding on IIS 7

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:

[ServiceContract]
public interface IService
{[OperationContract(IsOneWay=true)]
void GetData(int value);}

below is the service configuration:


<endpoint address=
“net.msmq://localhost/private/TestWCFMSMQ/Service.svc” binding=
“netMsmqBinding”
contract=”IService”
bindingConfiguration=”NoMsmqSecurity”/>
<endpoint address=”mex”
binding=”mexHttpBinding”
contract=”IMetadataExchange”/>

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:

ServiceReference1.ServiceClient proxy = new ServiceReference1.ServiceClient();using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
{
proxy.GetData(12);
scope.Complete();
}Console.WriteLine(“end”);
Console.Read();

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.

Advertisement

3 thoughts on “WCF NetMSMQBinding on IIS 7

  1. Mike

    *sigh*
    True to how MS does it, you are also missing vital tid-bits of informations in your documentation:

    To get this to work …
    (a) in your client project, add a reference o “System.Transactions”

    (b) in the .cs file of your console app, add “using System.Transactions;”

    Reply
  2. Linga Reddy

    I appreciate you about above clean explanation, it is understandable. But here I would like to know about the messages should be forwarded from the service to MSMQ means the WCF referenced application (client application) send message to WCF service then serive shoul pass that message to MSMQ.

    Just suggest me how to do this.

    Advance Thanks

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s