Jason Rowe

Be curious! Choose your own adventure.

NetMsmqBinding Brain Dump

I started experimenting with WCF’s NetMsmqBinding and found the abstraction to be a bit tricky. WCF takes care of all the MSMQ details and all you need to do is define the contract and do configuration. The following are some notes about that process.

Links

msmq wcf and iis getting them to play nice

AutoFac WAS Hosting and Non-HTTP Activation

Windows Components Installed

Microsoft Message Queue (MSMQ) Server > MSMQ Server Core

Microsoft .NET Framework > Windows Communication Foundation Non-HTTP Activation

IIS 7 Configuration

  1. Add net.msmq to the list of enabled protocols. In IIS, Web App -> Advanced Settings -> Enabled Protocols. It is a comma separated list (http,net.msmq).
  2. Make sure Client and Service have correct permissions to access the private queue

MSMQ Config

Add NETWORK SERVICE to the new MSMQ (windows 7 that is in Computer Managment -> Services and Applications -> Message Queuing

C# code to create initialize private queue

The queue name must match the URI of your service’s .svc file according to this

  // Create and connect to a private Message Queuing queue.
if (!MessageQueue.Exists(@".\Private$\JangoFettClient/CloneService.svc"))
{
    // Create the queue if it does not exist.
    MessageQueue.Create(@".\Private$\JangoFettClient/CloneService.svc");
}

Example Service Config

<bindings>
    <netMsmqBinding>
        <binding name="MsmqBindingNonTransactionalNoSecurity"
                        exactlyOnce="false">
            <security mode="None"/>
        </binding>
    </netMsmqBinding>
</bindings>
<services>
<service name="JangoFettClient.CloneService">
    <endpoint name="msmq" 
              address="net.msmq://localhost/private/JangoFettClient/CloneService.svc"
              binding="netMsmqBinding" 
              bindingConfiguration="MsmqBindingNonTransactionalNoSecurity"
              contract="JangoFettClient.ICloneOrderProcessor" />
</service>
</services>

Example Service

Example of data contract that would automatically become the listener and pull the items from MSMQ via WCF

namespace JangoFettClient
{
    public class CloneService : ICloneOrderProcessor
    {
        private readonly ILog _logger;

        public CloneService(ILog logger)
        {
            _logger = logger;
        }

        public void SendMessage(CloneOrder request)
        {
            _logger.Info("Message received from MSMQ");
        }
    }
}

Errors with easy fixes

The protocol ‘net.msmq’ is not supported. Add net.msmq to the list of enabled protocols. See IIS 7 Configuration above for more information.


Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *