简体   繁体   English

如何提取通过C#中的MSMQ从VB6发送的propertybag或复杂对象

[英]How to extract a propertybag or complex object send from VB6 through MSMQ in C#

I'm new to VB6 and also MSMQ. 我是VB6和MSMQ的新手。 I went through a lot of tutorials online but seems like there is no solution for my question. 我在线浏览了很多教程,但似乎没有解决我的问题的方法。

I managed to sending from C# to C# or VB6 to VB6 but not from VB6 to C# or vice versa. 我设法从C#发送到C#或从VB6发送到VB6,但没有从VB6发送到C#,反之亦然。 So I wonder is it a way to do that or there is no way to do this kind of communication. 所以我想知道这是一种方式还是没有这种沟通方式。

For example: I want to send this to MSMQ 例如:我想将此发送到MSMQ

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

and get the details in C#, there is "Invalid character in the given encoding. Line 1, position 1." 并获取C#中的详细信息,则存在“给定编码中的无效字符。第1行,位置1”。 error when I use XmlMessageFormatter XmlMessageFormatter时出现错误

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

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" 下面是代码,这是输出“늓\\ 0 \\ 0 \\ b \\ b휖ꭑ(\\ 0customer \\ 0Bob \\ 0 \\ b \\ aagent틠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);

I get this exception "Cannot deserialize the message passed as an argument. Cannot recognize the serialization format." 我收到此异常“无法反序列化作为参数传递的消息。无法识别序列化格式。” when using ActiveXMessageFormatter like below 当使用如下所示的ActiveXMessageFormatter时

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 提前致谢

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. 之前,我已经处理过这类问题,而我发现的最佳解决方案实际上是将对象序列化为XML-之后,使用哪种语言/平台以文本格式编码/解码该语言都无关紧要您将始终有选择。 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#). 在二进制格式中,您受即时格式化程序的支配,在整个平台(VB6 / C#)中不一定会以相同的方式工作。

Reference: http://www.codeproject.com/Articles/33296/Serialization-and-De-serialization 参考: http : //www.codeproject.com/Articles/33296/Serialization-and-De-serialization

In other words, you will need to have a standard serializer across both platforms and not try to serialize the propertybag itself. 换句话说,您将需要在两个平台上都有一个标准的序列化器,而不必尝试序列化propertybag本身。

The VB6 propertybag store data in binary format. VB6属性袋以二进制格式存储数据。 And you try to read the data in text format. 您尝试读取文本格式的数据。 That's the whole problem. 这就是整个问题。 Unrecognized characters - is a type and a size of the data in the PropertyBag.Try to make the exchange of data in binary form on both sides. 无法识别的字符-是PropertyBag中数据的类型和大小。请尝试在两侧进行二进制形式的数据交换。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM