1

So I'm trying to configure my client code to send messages to MSMQ queue. I followed the steps described in here: https://msdn.microsoft.com/en-us/library/ms789008(v=vs.100).aspx?cs-save-lang=1&cs-lang=csharp and my client code looks as below:

class Program
{
    static void Main(string[] args)
    {
        var binding = new MsmqIntegrationBinding("MyMessagesBinding");
        var address = new EndpointAddress(@"msmq.formatname:DIRECT = OS:.\private$\MyMessages");
        var channelFactory = new ChannelFactory<IDataRelayService>(binding, address);
        var channel = channelFactory.CreateChannel();

        while (true)
        {
            var message = new MyMessage
            {
                Content = "this is content!!!",
                Id = "random uuid"
            };
            var msmqWrapper = new MsmqMessage<MyMessage>(message)
            {
                Priority = MessagePriority.Highest
            };

            channel.PassMessage(msmqWrapper);
            Console.WriteLine("message sent");
            Console.ReadLine();
        }
    }
}

App.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
  </startup>
  <system.serviceModel>
    <client>
      <endpoint name="MyResponseEndpoint"
                address="msmq.formatname:DIRECT=OS:.\private$\MyMessages"
                binding="msmqIntegrationBinding"
                bindingConfiguration="MyMessagesBinding"
                contract="Client.IDataRelayService">
      </endpoint>
    </client>
    <bindings>
      <msmqIntegrationBinding>
        <binding name="MyMessagesBinding">
          <security mode="None" />
        </binding>
      </msmqIntegrationBinding>
    </bindings>
  </system.serviceModel>
</configuration>

IDataRelayService.cs:

[ServiceContract]
public interface IDataRelayService
{
    [OperationContract(IsOneWay = true, Action = "*")]
    void PassMessage(MsmqMessage<MyMessage> message);
}

IDataRelayServiceChannel.cs:

public interface IDataRelayServiceChannel : IDataRelayService, System.ServiceModel.IClientChannel
{
}

It compiles and runs with no problem, but when I open up evet viewer there are no events logged for MSMQ. If I open computer management tool to view queues it shows 0 messages in my queue. What am I doing wrong here?

EDIT:

I enabled event tracing for MSMQ and here's what event viewer is showing me:

enter image description here

Marek M.
  • 3,799
  • 9
  • 43
  • 93
  • It sounds like the messages are getting stored on the sender machine. Check the MSMQ service on the client's machine, and look for a temporary outbound queue. Your messages should be on it. – tom redfern Dec 12 '16 at 15:22
  • How can I see that? I'm looking at computer management / Message Queuing and I see no messages being held in my queue. Are you talking about some other tool by any chance? – Marek M. Dec 12 '16 at 16:26
  • Are you looking at the outgoing queues? – tom redfern Dec 12 '16 at 16:27
  • Outgoing queues is empty :( – Marek M. Dec 12 '16 at 16:30
  • And you have definitely enabled MSMQ event log on the receiver machine? – tom redfern Dec 12 '16 at 16:34
  • Well I right-clicked my queue name -> properties and checked the enabled checkbox in the journal section. Is that what you mean? Sorry, I'm quite new to this. Anyway - it's not showing any entries. – Marek M. Dec 12 '16 at 16:36
  • https://technet.microsoft.com/en-us/library/cc730882(v=ws.11).aspx – tom redfern Dec 12 '16 at 16:38

1 Answers1

0

Your problem is almost certainly permissions related.

The service account the message sender is running under must have the following MSMQ permissions on the queue it is trying to send to:

  • Send Message
  • Get Properties
  • Get Permissions

If your sender is on a different domain to your receiver, you will need to grant these permissions to a local user called ANONYMOUS_LOGON.

Also, enable MSMQ E2E event logging: https://technet.microsoft.com/en-us/library/cc730882(v=ws.11).aspx. This should tell you what is going on.

If you have WCF on both ends of the queue you should be using netMsmqBinding rather than msmqIntegrationBinding.

tom redfern
  • 30,562
  • 14
  • 91
  • 126