public void WriteToStream(Stream stream) { Fx.Assert(stream != null, "stream should not be null."); MtomMessageEncoder mtomMessageEncoder = this.messageEncoder as MtomMessageEncoder; if (mtomMessageEncoder == null) { this.messageEncoder.WriteMessage(this.message, stream); } else { mtomMessageEncoder.WriteMessage(this.message, stream, this.mtomBoundary); } }