Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
485 views
in Technique[技术] by (71.8m points)

c# - 消息队列错误:找不到能够读取消息的格式化程序(Message Queue Error: cannot find a formatter capable of reading message)

I'm writing messages to a Message Queue in C# as follows:

(我将消息写入C#中的消息队列,如下所示:)

queue.Send(new Message("message"));

I'm trying to read the messages as follows:

(我正在尝试阅读以下消息:)

Messages messages = queue.GetAllMessages();
foreach(Message m in messages)
{
  String message = m.Body;
  //do something with string
}

However I'm getting an error message which says: "Cannot find a formatter capable of reading this message."

(但是,我收到一条错误消息,内容为:“找不到能够读取此消息的格式化程序。”)

What am I doing wrong?

(我究竟做错了什么?)

  ask by macleojw translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I solved the problem by adding a formatter to each message.

(我通过向每个消息添加格式化程序解决了该问题。)

Adding a formatter to the queue didn't work.

(将格式化程序添加到队列中不起作用。)

Messages messages = queue.GetAllMessages();
foreach(Message m in messages)
{
  m.Formatter = new XmlMessageFormatter(new String[] { "System.String,mscorlib" });
  String message = m.Body;

  //do something with string
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...