Geeks With Blogs

News Awarded Microsoft MVP C#.NET - 2007, 2008 and 2009


I am born in Bangladesh and currently live in Melbourne, Australia. I am a Microsoft Certified Application Developer MCAD Chartered Member (C# .Net)and born in Bangladesh.
I am founder and Chief Executive Officer of
Simplexhub, a highly experienced software development company based in Melbourne Australia and Dhaka, Bangladesh. Co-founder and core developer of Pageflakes www.pageflakes.com.
Simplexhub, is on its mission to build a smart virtual community in Bangladesh and recently launched beta realestatebazaar.com.bd an ASP.NET MVC application written in C#.NET.


Some of My Articles
Flexible and Plugin based .Net Application..
Mass Emailing Functionality with C#, .NET 2.0, and Microsoft® SQL Server 2005 Service Broker'
Write your own Code Generator or Template Engine in .NET
Shahed Khan blog

I was Queuing a Serialized object in MSMQ. But soon realized that VB (legacy) do not like the format.

        public  void QueueJob(Job job, string destinationQueue, string messageLabel)
        {
            try
            {
                // open the queue
                MessageQueue mq = new MessageQueue(destinationQueue);
                // set the message to durable.
                mq.DefaultPropertiesToSend.Recoverable = true;
                // send the job object
                mq.Send(job, messageLabel);
                mq.Close();
            }
            catch (Exception e)
            {
                throw e;
            }
            
        }
 
The Queued Serialized Job Object was picked up by VB as "?????????????????"

For example when I queued a string= "Hello"

VB(Legacy) would pick up from the queue as "?????"

I did the opposite then to find out what is wrong:


I Queued from VB(legacy) "Hello"
I discovered via going through the Message.BodyStream of .Net that the stream is returning something like this: "H0\e0\l0\l0\o and was appending a "0\" in front of every character.

I soon realized that the default formatting of VB(legacy) and .Net Serialized object is not same.....

Soon discovered (after googling and from a link from my collegue) that Message should be Queued using ActiveXMessageFormatter for VB(legacy) to pick it correctly.
Here is the final code:

        public  void QueueJob(Job job, string destinationQueue, string messageLabel)
        {
            try
            {
                // open the queue
                MessageQueue mq = new MessageQueue(destinationQueue);
                // set the message to durable.
                mq.DefaultPropertiesToSend.Recoverable = true;
                // send the job object
                mq.Formatter = new ActiveXMessageFormatter();
                XmlSerializer xmlSer = new XmlSerializer(job.GetType());
                StringWriter sWriter = new StringWriter();
                // Serialize the job to xml.
                xmlSer.Serialize(sWriter, job);
                mq.Send(sWriter.ToString(), messageLabel);
                mq.Close();
            }
            catch (Exception e)
            {
                throw e;
            }
            
        }
What I have done here is got the string of the the Job object using the StringWriter after serializing it. And specified the Formatter to be ActiveXMessageFormatter, and then Send the message as usual to the Queue. Posted on Tuesday, February 13, 2007 2:50 AM | Back to top


Comments on this post: MSMQueuing from .Net for VB(legacy). Use ActiveXMessageFormatter

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Shahed Khan | Powered by: GeeksWithBlogs.net