473,397 Members | 1,960 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

MSMQ Serializing

I would appreciate help on the Microsoft Message Queue.

Basically I would like to Serialize an entire class into a message queue and
then reinstantiate the class in another application from the message queue
with all properties, variables etc in tact. What is the best way to do
this ie which formatter to use and how do you deal with arrays collections
properties etc defined in the class since there seems to be a limitation on
what you can serialize.

Thanks
Nov 21 '05 #1
1 3628
Hi

Here is a link about the formatting choosing suggestion. Basically the xml
ones will give more flexible, the binary ones will give more performance.

Send MSMQ Messages Securely Across the Internet with HTTP and SOAP
http://msdn.microsoft.com/msdnmag/is...T/default.aspx

Here is a link about Object Serialization

Object Serialization in Visual Basic .NET
http://msdn.microsoft.com/library/de...us/dnadvnet/ht
ml/vbnet09252001.asp

The link below is about how to send message using MSMQ in .net
BinaryMessageFormatter Class
http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfsystemmessagingbinarymessageformatterclasstop ic.asp

The link below is about how to do xml Serialization if you want to do the
xml format in msmq.
INFO: Roadmap for XML Serialization in the .NET Framework
http://support.microsoft.com/kb/314150/EN-US/

Here is some code snippet. Hope this will give some idea to get started.
[The Object definition sender side]
[System.Xml.Serialization.XmlRoot("RootName")]
public class TestObject
{
[XmlElement("MyArrayList",typeof(string))]
public ArrayList Info=new ArrayList();
public TestObject()
{
Info.Add("Hello");
}
}

[The Object definition receiver side]
[System.Xml.Serialization.XmlRoot("RootName")]
public class TestObject2
{
[XmlElement("MyArrayList",typeof(string))]
public ArrayList Info2;
}

[Code send and receive]
MyNewQueue myNewQueue = new MyNewQueue();
private void button1_Click(object sender, System.EventArgs e)
{
// Create a queue on the local computer.
MyNewQueue.CreateQueue(".\\myQueue");

// Send a message to a queue.
myNewQueue.SendMessage(new TestObject());

}

private void button2_Click(object sender, System.EventArgs e)
{
// Receive a message from a queue.
TestObject2 o2 = (TestObject2)myNewQueue.ReceiveMessage();

this.textBox2.Text = o2.Info2[0].ToString();
}

[The MyNewQueue class]
using System;
using System.Messaging;
using System.Drawing;
using System.IO;
using System.Collections;
using System.Xml;
using System.Xml.Serialization;
namespace TestMSMQ
{
/// <summary>
/// Provides a container class for the example.
/// </summary>
///

public class MyNewQueue
{

//**************************************************
// Creates a new queue.
//**************************************************

public static void CreateQueue(string queuePath)
{
try
{
if(!MessageQueue.Exists(queuePath))
{
MessageQueue.Create(queuePath);
}
else
{
Console.WriteLine(queuePath + " already exists.");
}
}
catch (MessageQueueException e)
{
Console.WriteLine(e.Message);
}

}
public void SendMessage(object o)
{
try
{

// Connect to a queue on the local computer.
MessageQueue myQueue = new MessageQueue(".\\myQueue");

Message myMessage = new Message(o, new XmlMessageFormatter(new
Type[]{typeof(TestObject)}));

// Send to the queue.
myQueue.Send(myMessage);
}
catch(ArgumentException e)
{
Console.WriteLine(e.Message);

}

return;
}
public object ReceiveMessage()
{

try
{

// Connect to the a queue on the local computer.
MessageQueue myQueue = new MessageQueue(".\\myQueue");

// Set the formatter to indicate body contains an Order.
myQueue.Formatter = new XmlMessageFormatter(new
Type[]{typeof(TestObject2)});

// Receive and format the message.
System.Messaging.Message myMessage = myQueue.Receive();
object o = (object)myMessage.Body;
return o;
}

catch (MessageQueueException)
{
// Handle Message Queuing exceptions.

}

// Handle invalid serialization format.
catch (InvalidOperationException e)
{
Console.WriteLine(e.Message);
}

catch (IOException e)
{
// Handle file access exceptions.
}

// Catch other exceptions as necessary.
return new object();

}
}
}

Hope this helps.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Andrew Gordon | last post by:
I'm investigating getting Microsoft Navision to do stuff from a Python script. The recommended way seems to be to use message queues (MSMQ). I can get Navision to send a message to itself fine. I...
3
by: Vai2000 | last post by:
hi all, I have a winsvc which reads of messages out an MSMQ. Can someone help with this problem. If my server goes down and comes back up my WinSvc doesn't picks up messages accumulated in the...
5
by: Alex Nitulescu | last post by:
Hi. I'm trying to make MSMQ work, so I go to Control Panel, Windows Components, I select MSMQ (Message Queuing Client Setup, actually) and about half-way through I get a nice message box saying ...
5
by: DBC User | last post by:
Hello, Is there an alternative approach to MSMQ for delivering messages? I am planning to develop an app which I don't want clients to install MSMQ (or do anything otherthan install my app). I...
1
by: m.i.mustafa | last post by:
I'm having problems with De-Serializing a complex object I'm sending through a queue. I call it a complex object simply because its a business object that is composed of other objects. Now all...
0
by: yonirabin | last post by:
Hello, I am building a system in C# 2.0 using the master - worker design pattern The system is supposed to work as follows: 1. The Master sends Command objects to the workers 2. All Commands are...
3
by: yonirabin | last post by:
Hello, I am building a system in C# 2.0 using the master - worker design pattern The system is supposed to work as follows: 1. The Master sends Command objects to several workers 2. All Commands...
11
by: Jon Davis | last post by:
Can a solution built in C# utilize MSMQ and/or MTS? If so, does this make the training material I already have on MSMQ and MTS in the context of VB6 an appropriate prerequisite foundation before...
1
by: Florence Tissot | last post by:
We are seeing some kind of resource leak in our performance lab running an ASP.NET (2.0) application that sends and receives messages from 2 public MSMQ queues. Here's a brief summary of what are...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.