posts - 234, comments - 480, trackbacks - 56

My Links

News




I am born in Bangladesh and currently live in Melbourne, Australia. I am a co-founder and core developer of Pageflakes www.pageflakes.com and CEO at Simplexhub, a highly experienced software development company based in Melbourne Australia and Dhaka, Bangladesh. 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.

I also created SmartCodeGenerator

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
Smart Code Generator .NET: Usage Overview
Smart Code Generator .NET: Architectural Overview
Smart Code Generator .NET: using with NAnt and Cassini

Archives

Free Programming Language Training

MSMQueuing from .Net for VB(legacy). Use ActiveXMessageFormatter

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.

Print | posted on Tuesday, February 13, 2007 2:50 AM |

Feedback

No comments posted yet.
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 
 

Powered by: