【发布时间】:2014-10-02 21:15:06
【问题描述】:
您将如何避免下面的 MSMQ 发送方和接收方创建的 InvalidOperationException?您能提供的任何帮助将不胜感激!
我感觉它可能与发送者的 BodyType 属性有关,但我不知道该属性的正确值域。
发件人代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Messaging;
namespace MSMQTester
{
class Program
{
static void Main(string[] args)
{
MessageQueue q = new MessageQueue(@"lab\test");
q.Formatter = new ActiveXMessageFormatter();
Message msg = new Message();
msg.Priority = MessagePriority.High;
msg.Body = "<hello_world />";
msg.Label = "test1";
q.Send(msg);
}
}
}
接收方代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Messaging;
namespace MSMQViewer
{
class Program
{
static void Main(string[] args)
{
MessageQueue q = new MessageQueue(@"lab\test");
q.Formatter = new ActiveXMessageFormatter();
while (true)
{
Message msg = q.Receive();
Console.WriteLine(msg.Body);
}
}
}
}
错误信息:
C:\dev\MSMQTester\MSMQViewer\bin\Debug>MSMQViewer.exe
未处理的异常:System.InvalidOperationException:无法反序列化我 ssage 作为参数传递。无法识别序列化格式。 在 System.Messaging.ActiveXMessageFormatter.Read(消息消息) 在 System.Messaging.Message.get_Body() 在 c:\dev\MSMQTester\MSMQViewer\Pro 中的 MSMQViewer.Program.Main(String[] args) gram.cs:第 18 行
【问题讨论】: