简体   繁体   English

通过msmqIntegrationBinding将消息发送到msmq队列

[英]Sending message to msmq queue via msmqIntegrationBinding

So I'm trying to configure my client code to send messages to MSMQ queue. 所以我正在尝试配置我的客户端代码以将消息发送到MSMQ队列。 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: 我按照这里描述的步骤进行了操作: https//msdn.microsoft.com/en-us/library/ms789008(v = vs.100).aspx?cs-save-lang = 1&ct-lang = csharp和我的客户代码看起来如下:

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: 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: IDataRelayService.cs:

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

IDataRelayServiceChannel.cs: 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. 它编译并运行没有问题,但是当我打开evet查看器时,没有为MSMQ记录任何事件。 If I open computer management tool to view queues it shows 0 messages in my queue. 如果我打开计算机管理工具来查看队列,它会在我的队列中显示0条消息。 What am I doing wrong here? 我在这做错了什么?

EDIT: 编辑:

I enabled event tracing for MSMQ and here's what event viewer is showing me: 我为MSMQ启用了事件跟踪,这是事件查看器向我显示的内容:

在此输入图像描述

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: 运行邮件发件人的服务帐户必须对其尝试发送到的队列具有以下MSMQ权限:

  • 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. 如果您的发件人与您的收件人位于不同的域,则需要将这些权限授予名为ANONYMOUS_LOGON的本地用户。

Also, enable MSMQ E2E event logging: https://technet.microsoft.com/en-us/library/cc730882(v=ws.11).aspx . 此外,启用MSMQ E2E事件记录: 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. 如果队列的两端都有WCF,则应使用netMsmqBinding而不是msmqIntegrationBinding。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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