我想从 C# WPF 应用程序中的消息队列中读取 XML 消息。消息由 Navision 代码单元保存到队列中。首先,我不确定保存在队列中的消息是否可用,因为它们是某种十六进制格式,如下所示:
FF FE 3C 00 3F 00 78 00 ÿþ<.?.x.
6D 00 6C 00 20 00 76 00 m.l. .v.
65 00 72 00 73 00 69 00 e.r.s.i.
6F 00 6E 00 3D 00 22 00 o.n.=.".
31 00 2E 00 30 00 22 00 1...0.".
20 00 65 00 6E 00 63 00 .e.n.c.
6F 00 64 00 69 00 6E 00 o.d.i.n.
67 00 3D 00 22 00 55 00 g.=.".U.
54 00 46 00 2D 00 31 00 T.F.-.1.
36 00 22 00 20 00 73 00 6.". .s.
74 00 61 00 6E 00 64 00 t.a.n.d.
61 00 6C 00 6F 00 6E 00 a.l.o.n.
...
从队列接收消息已经可以了,但不知何故格式错误,因为我得到这个运行时异常“无效操作异常:无法反序列化作为参数传递的消息。无法识别序列化格式。”
我正在使用此代码来阅读消息:
public MainWindow()
{
InitializeComponent();
mqCustomerData = new MessageQueue(@".\private$\customerData");
mqCustomerData.Formatter = new XmlMessageFormatter(new Type[] { typeof(String) });
mqCustomerData.ReceiveCompleted += new ReceiveCompletedEventHandler(mqCustomerData_ReceiveCompleted);
mqCustomerData.BeginReceive(new System.TimeSpan(0, 0, 0, 30));
}
private void mqCustomerData_ReceiveCompleted(object sender, System.Messaging.ReceiveCompletedEventArgs e)
{
Message m = new Message();
m.Formatter = new XmlMessageFormatter(new Type[] { typeof(String) });
m = mqCustomerData.EndReceive(e.AsyncResult);
string text = (string)m.Body;
}
我已经搜索了这个问题,但没有找到有用的解决方案,只找到了其他用户遇到同样问题的帖子,比如这里:http ://www.webmasterworld.com/microsoft_asp_net/4119362.htm
我希望你们中的某个人可以帮助我:)