【问题标题】:msmq AppSpecific was not retrieved when receiving the message收到消息时未检索到 msmq AppSpecific
【发布时间】:2019-09-07 16:46:51
【问题描述】:

我想使用 MSMQ 传输消息。当我发送消息时,我将枚举 (StudentMessageType) 作为 AppSpecific 传递,这样我就可以识别在目的地应该做什么。但是当我尝试接收消息时,我无法访问 AppSpecific 属性并且我得到了这个异常:

接收消息时未检索到属性 AppSpecific。 确保 PropertyFilter 设置正确。

我应该怎么做才能收到 AppSpecific?

发送

var requestQueue = new MessageQueue(@".\private$\req");
requestQueue.MessageReadPropertyFilter.AppSpecific = true;
requestQueue.Formatter = new BinaryMessageFormatter();
Message studentNameMessage = new Message(studentName, new BinaryMessageFormatter());
studentNameMessage.AppSpecific = (int) Student.StudentMessageType.AddStudent;
requestQueue.Send(studentNameMessage, MessageQueueTransactionType.Single);
requestQueue.Close();

接收

requestQueue = new MessageQueue(@".\private$\req");
requestQueue.Formatter = new BinaryMessageFormatter();
MessageQueueTransaction transaction = new MessageQueueTransaction();
    try
        {
        transaction.Begin();
                Message message = requestQueue.Receive(transaction);
                output = (string)message.Body;
                output += "\t" + ((Student.StudentMessageType) message.AppSpecific).ToString();
                transaction.Commit();
        }
    catch (Exception e)
        {
                Console.WriteLine(e);
                throw;
        }

【问题讨论】:

  • 查看示例。我有两个问题 1) 为什么你有美元符号? 2)您在哪里将消息附加到正文?这是示例:docs.microsoft.com/en-us/dotnet/api/…
  • @jdweng 1. 我不知道为什么! 2.Message构造函数的First Argument(我得到正确的消息,我只是没有得到AppSpecific)
  • 我认为您的意思是您收到了回复,但消息为空。好吧,如果你不把任何东西放在身体里,你就不会得到 AppSpecific。
  • @jdweng 我得到一个响应,它不是空的,它是我传递给消息对象(studentName)的第一个参数的字符串。

标签: c# msmq


【解决方案1】:

omg,我只是忘记了接收方法中的这一行:

requestQueue.MessageReadPropertyFilter.AppSpecific = true;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-07-12
    • 2023-03-21
    • 2011-09-22
    • 1970-01-01
    • 2023-03-07
    • 2014-05-24
    • 2011-06-22
    • 2023-03-27
    相关资源
    最近更新 更多