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.