• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 666
  • Last Modified:

Messageformat of MSMQ messages sent between VC7++ and .NET?

Hi everybody! Got a question for ya...

I have a mainsystem running VC7++ with all classes derived from CObject and implementing the Serialize()-method to serialize the class to a CByteArray. I use MSMQ to send messages ( the body is an ByteArray ) within this system and thus I can deserialize the message at the reciever successfully while it understands what a CByteArray is. This works fine for me and I´ve done some wrappers for this...

Now I have another system running .NET and I which to recieve/send the message from/to the mainsystem. While the messages sent in the mainsystem is CByteArray´s I cannot unpack this successfullly in the .NET environment.... I would like to, in some way, to be able to send/recieve messages between these 2 systems and now I would like some advise in selecting a format of the message that both systems understand.

I have the ability to change the code of the mainsystem to suite the needs of the .NET enironment but there´s many classes sent in the mainsystem with MSMQ that I rather not change these classes too much....  Can I in some way in VC7++ serialize/deserialize a class into/from XML ( with a schema )?

1. What message-format should I use to be able send/recieve messages between these 2 systems?

I´m rather new to XML ( Most of the programming I´ve done is actually in VC6++ ) so have that in mind when answering : )

Messages sent in the mainsystem can contain NULL-signs....
0
TYB
Asked:
TYB
  • 3
  • 2
1 Solution
 
ambienceCommented:
>> Can I in some way in VC7++ serialize/deserialize a class into/from XML ( with a schema )?

Sure you can. Using XML is one of the way of (and probably the most portable) communicating between the two. Expecially if your objects can be easily serialized into XML.

>> While the messages sent in the mainsystem is CByteArray´s I cannot unpack this successfullly in the .NET environment.

If you are trying to use .NET deserialization, then it fails understandably. .NET serialization requires a specific format of the stream, which also includes meta data about the assemblies and classes involved. A bit OT but maybe scanning the following link may help understand the possibilities that you may have.

http://msdn.microsoft.com/msdnmag/issues/02/04/net/
http://msdn.microsoft.com/msdnmag/issues/02/07/net/
http://msdn.microsoft.com/msdnmag/issues/02/09/net/

What you can do is to define a common binary format of the messages between the two systems. When you send something from C++ package the data into that binary struct and send it as a byte array (the way you would if writing a TCP based app). When in .NET you have to receive the message as raw bytes (fill in a byte array). From that byte array you can reconstruct the objects in .NET.

hope this helps ...
0
 
TYBAuthor Commented:
Tnx for your answer.

Can I create a create a class in VC7++ ( derived from CObject to have serialization support I suppose, or else what class? ), serialize it to a CByteArray and then send it to the .NET (C#) enivronment and that environment will understand how to unpack that class?

>> What you can do is to define a common binary format of the messages between the two systems. When you send something from C++ package the data into that binary struct and send it as a byte array (the way >> you would if writing a TCP based app). When in .NET you have to receive the message as raw bytes (fill in a byte array). From that byte array you can reconstruct the objects in .NET.

Can you give me an example of what you mean?
0
 
TYBAuthor Commented:
Can I create a xml -file in VC7++ that has the same format and that the .NET environment understands?  ... in .NET it´s very simple to serialize a class into XML..but can I do that as simple in VC7++?
0
 
ambienceCommented:
>> Can I create a create a class in VC7++ ( derived from CObject to have serialization support I suppose, or else what class? )

Well somethings tells me that you are reffering to the Serialization support provided by MFC (CArchive, IMPLEMENT_SERIAL etc.). True that you'll be able to serialize the contents of the objects to a CArchive and load it back from that, but thats it. You are limited to using a CArchive. Moreover MFC has special means of serializing the whole graph to a stream and loading it back from there, and thus it puts in meta data about the classes. "The point is you are limited to MFC only".

>> serialize it to a CByteArray and then send it to the .NET (C#) enivronment and that environment will understand how to unpack that class?

How are you converting the byte array to a variant? MSMQ message body ought to be a variant. Can post some code?

>> Can I create a xml -file in VC7++ that has the same format and that the .NET environment understands?  

Yes, when you send it as XML you are free to define the Structure of your XML the way you like it. Thats the beauty of XML. Structure it anyway you like (as long as it remains valid XML). for example

if you have an object like

struct myInfo
{
     int   value;
     char name[256];
}

you can have the XML as

<myInfo>
    <value>10</value>
    <name>Test</name>
</myInfo>

or

<myInfo value="10" name="Test"/>

or any other structure you preffer. The only thing important is that the sender and the receiver must agree of a common structure, so that both know what to expect.

>> in .NET it´s very simple to serialize a class into XML..but can I do that as simple in VC7++?

Unfortunately no, but as you may see from the example its not a big deal at all. You may form the XML using simple string concatetation only. Or use a class that provides basic XML formatting (see www.codeproject.com, www.codeguru.com). Or even use a full blown parser (MsXml 4.0, see MSDN for further information). A parser can be handy when you are on the receiving end, otherwise all you need is an XML string no matter how you get it.


0
 
TYBAuthor Commented:
Tnx for your answer ..been away for a while so I´m sorry for not accepting your answer yet.

We bought Liquid Technologies Data Binding Wizard for generating C++ classes that can generate XML documents...  

works fine now....  
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now