Search code examples
wcfmsmq

MSMQ receives messages only from some Clients


I have a WCF service where client applications can connect via a MSMQ:

[ServiceContract(Namespace="http://example.com", SessionMode = SessionMode.NotAllowed)]
public interface IMyService
{
    [OperationContract(IsOneWay = true)]
    void Update(DataSet ds);
}

and then:

string queueName = ConfigurationManager.AppSettings["QueueName"];
NetMsmqBinding binding = new NetMsmqBinding("MyBinding");

if (!MessageQueue.Exists(@".\private$\" + queueName))
{
    MessageQueue.Create(@".\private$\" + queueName, binding.ExactlyOnce);
}

ServiceHost msmqHost = new ServiceHost(typeof(MyService));
msmqHost.AddServiceEndpoint(typeof(IMyService), binding, "net.msmq://localhost/private/" + queueName);

with the following configuration:

  <system.serviceModel>
    <bindings>
      <netMsmqBinding>
        <binding name="MyBinding" durable="false" exactlyOnce="false" maxReceivedMessageSize="20000000">
          <security mode="None" />
          <readerQuotas maxDepth="32" maxStringContentLength="543192" maxArrayLength="2147483647" maxBytesPerRead="4096" maxNameTableCharCount="8456384" />
        </binding>
      </netMsmqBinding>
    </bindings>
    <services>
      <service name="MyService" behaviorConfiguration="MsMqBehavior" />
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="MsMqBehavior">
          <serviceThrottling maxConcurrentCalls="50" maxConcurrentSessions="50" maxConcurrentInstances="50" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

I have the service with the same configuration already in use without problems on other installations. But now on a new installation I receive only messages from some clients (9 actually - there are 31). The messages I receive are always from the same servers. I can't find an error message anywhere (Windows Event Log (Client/Server), WCF Trace file) and also the MSMQ state says "connected" on the client machines that don't send messages. The dead letter queues are also empty.

The messages must get lost somewhere between the MSMQ Client and Server (I stopped my app and on the server queue I received only messages from the nine Clients - same behaviour if I enable journaling).

Any help would be appreciated

Update

I've used performance counters to monitor the queue. The session counter shows the correct value of 31 sessions. Also the incoming message counter shows correct values. However if I stop the app or enable journaling only a part of the messages are stored in the queue.


Solution

  • The problem comes through cloning the server as described in this blog entry: http://blogs.msdn.com/b/johnbreakwell/archive/2007/02/06/msmq-prefers-to-be-unique.aspx

    Basically it says there that you must not clone servers with MSMQ feature turned on. If you do so you either have to re-install the MSMQ feature on your client machines or do a registry change:

    1.Stop the MSMQ Service
    2.Delete the QMId value completely
    3.Add a SysPrep DWORD (Under HKLM\Software\Microsoft\MSMQ\Parameters) and set it to 1
    4.Start the MSMQ Service