如何提取通过C#中的MSMQ从VB6发送的propertybag或复杂对象 [英] How to extract a propertybag or complex object send from VB6 through MSMQ in C#

查看:165
本文介绍了如何提取通过C#中的MSMQ从VB6发送的propertybag或复杂对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是VB6和MSMQ的新手.我在线上浏览了很多教程,但似乎我的问题没有解决办法.

I'm new to VB6 and also MSMQ. I went through a lot of tutorials online but seems like there is no solution for my question.

我设法从C#发送到C#或从VB6发送到VB6,但没有从VB6发送到C#,反之亦然.所以我想知道这是一种方式还是没有这种方式的沟通.

I managed to sending from C# to C# or VB6 to VB6 but not from VB6 to C# or vice versa. So I wonder is it a way to do that or there is no way to do this kind of communication.

例如:我想将其发送给MSMQ

For example: I want to send this to MSMQ

Dim PropBag As PropertyBag
 Set PropBag = New PropertyBag
 PropBag.WriteProperty "Customer", "Bob"
 PropBag.WriteProperty "Product", "MoeHairSuit"
 PropBag.WriteProperty "Quantity", 4

并在C#中获取详细信息,在给定的编码中有无效字符.第1行,位置1". XmlMessageFormatter出现错误

and get the details in C#, there is "Invalid character in the given encoding. Line 1, position 1." error when I use XmlMessageFormatter

Message mes = mq.Receive(new TimeSpan(0, 0, 3));
mes.Formatter = new XmlMessageFormatter(new String[] { "System.String,mscorlib" });
result = mes.Body.ToString();

我也尝试从流中读取内容,但它在字符串中带有一个奇怪的符号.下面是代码,这是输出늓\ 0 \ 0 \ b \ b휖ꭑ(\ 0customer \ 0Bob \ 0 \ b \ aagent틠4 \ 0product \ v \ 0MoeHairSuit \ b调⫳ᄂ .quantity \ 0 "

I also tried to read from the stream but it come out with a weird symbol in my string. Below is the code and this is the output "늓\0\0\b\b휖ꭑ(\0customer\0Bob\0\b\a劑틠4\0product\v\0MoeHairSuit\b調⫳ᄂ.quantity\0"

Message mes;
mes = mq.Receive(new TimeSpan(0, 0, 3));
mes.BodyStream.Position = 0;
byte[] b = new byte[mes.BodyStream.Length];
mes.BodyStream.Read(b, 0, (int)mes.BodyStream.Length);
UnicodeEncoding uniCoder = new UnicodeEncoding();
result = uniCoder.GetString(b);

我收到此异常无法反序列化作为参数传递的消息.无法识别序列化格式."当使用如下所示的ActiveXMessageFormatter时

I get this exception "Cannot deserialize the message passed as an argument. Cannot recognize the serialization format." when using ActiveXMessageFormatter like below

mes = mq.Receive(new TimeSpan(0, 0, 3));
mes.Formatter = new ActiveXMessageFormatter();
result = mes.Body.ToString();

你们有什么想法吗? 在此先感谢

Do you guys have any idea how to do that? Thanks in advanced

推荐答案

我之前已经处理过此类问题,而我发现的最佳解决方案实际上是将对象序列化为XML-之后就没有了无论您使用哪种语言/平台来对语言进行编码/解码(如文本格式),您始终可以选择.对于二进制格式,您受即时格式化程序的支配,在整个平台(VB6/C#)中不一定会以相同的方式工作.

I've dealt with this type of problem before and the best solution that I've found is actually to serialize the object into XML - afterwards it doesn't matter what language/platform you use to encode/decode the language as in text format you will always have options. In binary format you are at the mercy of the immediate formatter which won't necessarily work the same way across the platforms (VB6/C#).

参考: http://www.codeproject.com/Articles/33296/Serialization-and -反序列化

换句话说,您将需要在两个平台上都有一个标准的序列化程序,而不要尝试对propertybag本身进行序列化.

In other words, you will need to have a standard serializer across both platforms and not try to serialize the propertybag itself.

这篇关于如何提取通过C#中的MSMQ从VB6发送的propertybag或复杂对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆