473,834 Members | 1,417 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3669
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.a sp

The link below is about how to send message using MSMQ in .net
BinaryMessageFo rmatter Class
http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfsystemmess agingbinarymess ageformattercla sstopic.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.Seri alization.XmlRo ot("RootName")]
public class TestObject
{
[XmlElement("MyA rrayList",typeo f(string))]
public ArrayList Info=new ArrayList();
public TestObject()
{
Info.Add("Hello ");
}
}

[The Object definition receiver side]
[System.Xml.Seri alization.XmlRo ot("RootName")]
public class TestObject2
{
[XmlElement("MyA rrayList",typeo f(string))]
public ArrayList Info2;
}

[Code send and receive]
MyNewQueue myNewQueue = new MyNewQueue();
private void button1_Click(o bject sender, System.EventArg s e)
{
// Create a queue on the local computer.
MyNewQueue.Crea teQueue(".\\myQ ueue");

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

}

private void button2_Click(o bject sender, System.EventArg s e)
{
// Receive a message from a queue.
TestObject2 o2 = (TestObject2)my NewQueue.Receiv eMessage();

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

[The MyNewQueue class]
using System;
using System.Messagin g;
using System.Drawing;
using System.IO;
using System.Collecti ons;
using System.Xml;
using System.Xml.Seri alization;
namespace TestMSMQ
{
/// <summary>
/// Provides a container class for the example.
/// </summary>
///

public class MyNewQueue
{

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

public static void CreateQueue(str ing queuePath)
{
try
{
if(!MessageQueu e.Exists(queueP ath))
{
MessageQueue.Cr eate(queuePath) ;
}
else
{
Console.WriteLi ne(queuePath + " already exists.");
}
}
catch (MessageQueueEx ception e)
{
Console.WriteLi ne(e.Message);
}

}
public void SendMessage(obj ect o)
{
try
{

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

Message myMessage = new Message(o, new XmlMessageForma tter(new
Type[]{typeof(TestObj ect)}));

// Send to the queue.
myQueue.Send(my Message);
}
catch(ArgumentE xception e)
{
Console.WriteLi ne(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.Formatt er = new XmlMessageForma tter(new
Type[]{typeof(TestObj ect2)});

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

catch (MessageQueueEx ception)
{
// Handle Message Queuing exceptions.

}

// Handle invalid serialization format.
catch (InvalidOperati onException e)
{
Console.WriteLi ne(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.c om/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
3729
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 found a couple of code example in an ancient message in this newsgroup. The send.py one I changed to the following: from win32com.client import gencache msmq = gencache.EnsureModule('{D7D6E071-DCCD-11D0-AA4B-0060970DEBAE}', 0, 1, 0) qi =...
3
5809
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 MSMQ , although my WinSvc is set to automatic restart setting. I have to manually go and restart the service then only it retrieves all the messages from the MSMQ. This is the code..... /////////////////////////////////////////
5
11670
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 The MSMQ service cannot be started. Error code: 0x42C The Dependency service or group failed to start. If I acknowledge, the "installation" continues as if nothing happened, but in the end nothing has been installed.
5
6385
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 was want to pass messages between two programs and my first approach was MSMQ and it worked perfectly and then I found out MSMQ is a seperate win component and is not installed by default. I am looking at writing files and implement...
1
2408
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 the objects are serializable, and they get placed in the queue with no problems, but on the receiving end, all the values are null. does anyone have any ideas? Thanks in Advance,
0
1417
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 derived from AbstractCommand class since the system is distributed and should be presistant, I want to use MSMQ to pass the Command object to the Workers The object which I send to the MSMQ is a message containing an object
3
6395
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 are derived from AbstractCommand class (but are significantly different from each other) Since the system is distributed and should be presistant, I want to use
11
3589
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 learning how to build C# solutions on MSMQ / MTS, if I already know VB6 as well as C#? Jon
1
4783
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 application does: 1. user provides input on a form on an aspx page and clicks continues 2. on postback, the page creates a c# .net object and calls a method on it to process the data provided by the user 3. the object in turns creates an...
0
9796
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10790
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10505
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10545
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7755
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5624
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5790
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4425
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3976
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.