简体   繁体   中英

Sending message to msmq queue via msmqIntegrationBinding

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:

在此输入图像描述

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM