MSMQ and hashtable

Source: Internet
Author: User
Tags msmq
It is in use today. net encountered a small problem when operating the message queue. If xmlmessageformatter is used to serialize the message body, the message body cannot contain fields such as hashtable, otherwise, serialization and deserialization will fail (even if the message body object is added with the serializable feature ).
After research, we found that xmlmessageformatter does not use the binary or soap format that we often use for. Net remoting serialization, but uses the XML format. Therefore, the serializable label does not work for xmlmessageformatter. The message body objects supported by xmlmessageformatter can only contain some very simple basic type fields.
To embed a type like hashtable into a message body, we only use binarymessageformatter and binarymessageformatter. net remoting is the same as the Runtime Library serialization mechanism, so the serializable feature label will be recognized by binarymessageformatter, and we must add the serializable feature to the object as the message body to use binarymessageformatter.
If we use binarymessageformatter like this, an exception that cannot be serialized will still be thrown: Public void senditem (mqitem item)
{
System. messaging. Message MSG = new system. messaging. Message ();
MSG. Body = item;
MSG. Label = "mqitem ";
This. msgqueueforsend. Send (MSG); // This. msgqueueforsend. formatter = new binarymessageformatter ();
}


But it will be normal if it is changed to the following: Public void senditem (mqitem item)
{
System. messaging. Message MSG = new system. messaging. Message (item, new binarymessageformatter ());
MSG. Label = "mqitem ";
This. msgqueueforsend. Send (MSG );
}

I don't know why.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.