// send
MessageQueue q = new MessageQueue(***);
XmlDocument doc = new XmlDocument();
// create doc and add root node and child nodes
doc.AppendChild(doc.CreateElement("Root"));
...
// this gets the entire body of the xml document
// into the message without being encoded
q.Send(doc,"XmlDocument Message");
// receive
MessageQueue q = new MessageQueue(***);
q.Formatter =
new XmlMessageFormatter(new Type[] { typeof(XmlDocument) });
Message m = q.Receive();
// this bombs out
XmlDocument doc = (XmlDocument)m.Body;
gives me "PMSystem.InvalidOperationException: Cannot deserialize the
message passed as an argument. Cannot recognize the serialization
format."
I know the message is a valid XmlDocument as I can read the BodyStream
and load it into the document using LoadXml() with no problems, but I
should be able to cast the Body property to an XmlDocument and use it
without jumping through hoops.
Any ideas?
Aaron
If you have an XmlDocument object and System.Messaging on both ends,
wouldn't it be simpler to just use BodyStream?
// Send
MessageQueue q = new MessageQueue(***);
XmlDocument doc = new XmlDocument();
doc.AppendChild(doc.CreateElement("Root"));
Message m = new Message ();
doc.Save (m.BodyStream)
q.Send(doc,"XmlDocument Message");
// Receive
MessageQueue q = new MessageQueue(***);
Message m = q.Receive();
XmlDocument doc = new XmlDocument ();
doc.Load (m.BodyStream);
> I know the message is a valid XmlDocument as I can read the BodyStream
> and load it into the document using LoadXml() with no problems,
The message may contain valid XML but I don't think it contains a valid
XmlMessageFormatter serialisation of an XmlDocument object which is what it
would have to be for XmlMessageFormatter to de-serialise it back into an
XmlDocument.
I think the problem is that an XmlSerializer doesn't properly handle the
XmlDocument instance. If you run doc through XmlSerializer.Serialize and
then try to run it back through Deserialize you'll find that Deserialize
fails, with an exception indicating that the root element is missing.
Off hand it isn't clear whether this is a bug in XmlSerializer or if
XmlDocument is just a class which cannot be serialized. However I suspect
the latter. XmlDocument implements IEnumerable but doesn't have an Add
method. The XmlSerializer requires that classes which implement IEnumerable
have an Add method, so XmlDocument seems to break the rules for XML
Serialization.
I ended up just using the stream methods and properties, I just didn't
understand why it serialized with no errors, but then wouldn't
deserialize properly. I would think that it should give an error when
serializing if it can't deserialize it on the other end. Not much
point otherwise.
Aaron
"Frank Boyne" <frank...@unisys.com> wrote in message news:<#xvBwyvACHA.1680@tkmsftngp05>...