Introducing MessageState
I've mentioned that messages have a definite lifecycle without ever mentioning what the lifecycle represents. The MessageState enumeration reflects the different stages that a message goes through.
public enum MessageState
{
Created = 0,
Read = 1,
Written = 2,
Copied = 3,
Closed = 4,
}
Messages initially start off in the Created state. The simplest way of thinking about this is that Created messages are the only type of messages that are valid to use. Messages are restricted to a single use so that we can support the programming model of operating on transient, streaming content. Every other message state reflects how the message lived its life.
By calling GetReaderAtBodyContents, you move the message to the Read state. This reflects a message that has been killed by consuming its contents using an XmlReader.
By calling either WriteBodyContents or WriteMessage, you move the message to the Written state. This reflects a message that has been killed by consuming its contents using an XmlWriter.
By calling CreateBufferedCopy, you move the message to the Copied state. This reflects a message that has been killed by consuming its contents using a MessageBuffer. Copying the message to a buffer is the easiest way of using the contents of a message more than once. Unlike a transient message, buffers are something that can survive repeated use.
A message in the Closed state has been cleaned up by calling Close or the equivalent Dispose. An implementation may have other methods that in turn invoke one of these five deadly message poisons. Messages are lightweight objects that are not thread-safe. If you call multiple methods that affect the message state at the same time, then you'll very likely screw up your program. Don't do that.
Next time: Net.Tcp Port Sharing Sample, Part 1
Comments
- Anonymous
August 03, 2006
Love the reference to "Five Deadly Venoms"... Awesome. - Anonymous
August 03, 2006
The last cipher I'm going to talk about is the Advanced Encryption Standard (AES). With this, we'll... - Anonymous
February 19, 2007
I haven't forgotten about the goal to put together a table of contents for all of these articles. The