none
Send and Receive hashtable as message into message queue using c# RRS feed

  • Question

  • Hi all,

      I want to send and receive hashtable as messages to the message queue in c#.

    Please anyone help me to solve this as soon as possible.

    Thanks,


    Prabhakaran.K

    Saturday, September 22, 2012 12:10 PM

Answers

  • Try using this

    public static void SendMessage(object objBody, string idlable)
    {
    	try
    	{
    		//Body can be anythig( your hashtable or wrapper class)
    		Message msg = new Message(objBody);
    		msg.Label = idlable;
    		
    		YourMesssageQueue.Send( msg );
    	}
    	catch( Exception ex )
    	{
    		
    	}
    }
    
    
    //Reading
    void ReaderQueue_OnMessageRecieve( Message msg )
    {
    	try
    	{
    		if( msg == null )
    			return;
    
    		switch( msg.Label )
    		{
    			case idlable:
    			msg.Formatter = new XmlMessageFormatter( new[] { typeof( (yourHastable) or wrapper class or structure) } );
    			HashTable data = (HashTable) msg.Body;
    			break;
    		}
    	}
    }
    


    Thanks for the help!

    Sunday, September 23, 2012 6:22 AM

All replies

  • If you are using System.Messaging.MessageQueue.Send, it accepts an object for the item being sent.  Can you describe your problem further, and include a small code example that might help understand your issue with this call?

    --
    Mike
    Saturday, September 22, 2012 12:43 PM
  • Try using this

    public static void SendMessage(object objBody, string idlable)
    {
    	try
    	{
    		//Body can be anythig( your hashtable or wrapper class)
    		Message msg = new Message(objBody);
    		msg.Label = idlable;
    		
    		YourMesssageQueue.Send( msg );
    	}
    	catch( Exception ex )
    	{
    		
    	}
    }
    
    
    //Reading
    void ReaderQueue_OnMessageRecieve( Message msg )
    {
    	try
    	{
    		if( msg == null )
    			return;
    
    		switch( msg.Label )
    		{
    			case idlable:
    			msg.Formatter = new XmlMessageFormatter( new[] { typeof( (yourHastable) or wrapper class or structure) } );
    			HashTable data = (HashTable) msg.Body;
    			break;
    		}
    	}
    }
    


    Thanks for the help!

    Sunday, September 23, 2012 6:22 AM
  • The Jiten post is a perfect answer, but use MSMQ technology (in my opinion ) is considered to be a deprecated.

    i suggest you to use the WCF methodology:

    http://msdn.microsoft.com/en-us/library/ms789048.aspx

    http://www.codeproject.com/Articles/326909/Creating-a-WCF-Service-with-MSMQ-Communication-and

    Sunday, September 23, 2012 7:22 PM