how can i serialize a object received from a MessageQueue?

I am sending to a message queue objects of a type "employee" ( a type that i created), sending part executes properly..

i need to know how i can retrieve the objects properly, how can i serialize it back to "employee" type

currently i'm using the following code.. it doesnt work..

BinaryFormatter binaryFormatter = new BinaryFormatter();

MessageQueue msgQueue = new MessageQueue(MessageQueueName);

System.Messaging.Message msg = msgQueue.Receive();

msg.Formatter = new System.Messaging.XmlMessageFormatter(new string[] { "System.String" });

Employee emp = (Employee)msg.Formatter;

MessageBox.Show(emp.Name);



Answer this question

how can i serialize a object received from a MessageQueue?

  • eric shih

     Sachitha wrote:

    System.Messaging.Message msg = msgQueue.Receive();

    msg.Formatter = new System.Messaging.XmlMessageFormatter(new string[] { "System.String" });

    Employee emp = (Employee)msg.Formatter; 

    You evaluate the emp with msg.Formatter which returns an IMessageFormatter interface type. So you must implement the interface in the employee class to be compatible to Formatter property.

    Here is the signature:

    public IMessageFormatter Formatter { get; set; }


  • AFM

    no i haven't used that.. Do i need to use IMessageFormatter when i 'm sending messages to the MSMQ as well
  • AHTUNG

    Hi,

    Have you implemented the IMessageFormatter in your "emplayee" class

    Cause msg.Formatter return an object which must have implementation of this interface.

    Thank you



  • how can i serialize a object received from a MessageQueue?