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.