By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,660 Members | 1,735 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,660 IT Pros & Developers. It's quick & easy.

Q: How to send/receive XmlDocument objects via a message queue?

P: n/a
I'm trying to send and receive XmlDocument objects using the
System.Messaging.dll functions. The code I've written follows, as best I
can tell, the methodology used in the sample code for the
XmlMessageFormatter class. But it isn't working -- specifically, receiving
isn't working. What am I doing wrong here?

I begin by creating a MessageQueue object and setting up its
XmlMessageFormatter to handle XmlDocument objects:

System.Type[] types = { System.Type.GetType("XmlDocument") };
XmlMessageFormatter fmt = new XmlMessageFormatter(types);
queue = new MessageQueue(queueName);
queue.Formatter = fmt;

I can then use the queue object to send XmlDocument messages with no
problem:

XmlDocument doc = new XmlDocument();
doc.LoadXml("<msg/>");
doc.DocumentElement.SetAttribute("time", String.Format("{0}",
DateTime.Now));
queue.Send(doc);

But receiving these messages doesn't work:

Message msg = queue.Receive(TimeSpan.Zero);
XmlDocument doc = (XmlDocument) msg.Body;

throws this exception:

An unhandled exception of type 'System.ArgumentNullException' occurred
in mscorlib.dll
Additional information: Key cannot be null.

I can readily work around this problem. I just need to set up the
XmlMessageFormatter object to handle String objects instead of XmlDocument
objects. Then on sending, I send the doc.OuterXml property, and I receive
with this code:

Message msg = queue.Receive(TimeSpan.Zero);
XmlDocument doc = new XmlDocument();
doc.LoadXml((string) msg.Body);

But I'd sure like to know why the code I've written doesn't work.

Bob Rossney
rb*@well.com
Nov 12 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Hi Robert,

We have reviewed your post. We will do some research on your issue and will
reply to you ASAP.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 12 '05 #2

P: n/a
Hi Robert!

Thanks for using the Microsoft Newsgroups. Carl Huber is one of our
support team members and will be replying to your issue ASAP. He is
currently investigating your problem. In the meantime, if you have any
questions, please feel free to reply to me and I will help you as best I
can.

Brett Keown
Microsoft Support
br*****@online.microsoft.com

This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 12 '05 #3

P: n/a
Hi Robert,

I've done some research on this issue and so far it appears the problem is
that the XMLDocument object is not marked as serializable. I haven't
confirmed this yet but I'm pretty sure that's the reason.

I'll let you know for sure when I have more information. Hope this helps.

Regards,
Carl Huber, MCSD
Microsoft Developer Support/Visual Basic WebData
This posting is provided "AS IS" with no warranties, and confers no rights.
Get Secure! -> http://www.microsoft.com/security

Nov 12 '05 #4

P: n/a
Hi Robert,

I just wanted to let you know I'm still researching the issue. As soon as
I have more information, I will post it.

Regards,
Carl Huber, MCSD
Microsoft Developer Support/Visual Basic WebData
This posting is provided "AS IS" with no warranties, and confers no rights.
Get Secure! -> http://www.microsoft.com/security

Nov 12 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.