Now that we have seen how to create, serialize, and deserialize a Message, let’s turn our attention to an important read-only property of the Message type named State. The Message type is stateful, and Message state can be described through a variety of means. Like any reference type, the state of a Message is the combination of the values of its fields, but this is not strictly what the State property of a Message represents. The State property of a Message represents the value of one private field of type MessageState (called state). As shown here, MessageState is an enumerated type that defines five possible values: Created, Read, Written, Copied, and Closed.
namespace System.ServiceModel.Channels { public enum MessageState { Created = 0, Read = 1, Written = 2, Copied = 3, Closed = 4, } }
The value of the State property of a Message object changes when certain methods are called on that Message object. Internally, concrete implementations of the Message type use the State property to manage the order in which methods are called on a Message object. For example, anytime a message is created via one of the Message.CreateMessage factory methods, its State is set to Created; calling any of the methods that start with the word Write changes the State to Written; etc.