Assembly: System.Runtime.Serialization (in system.runtime.serialization.dll)
Write any necessary information preceding the stream (For example, the opening XML tag).
Write the stream.
Write any information following the stream (For example, the closing XML tag).
This works well with encodings that are similar to the textual XML encoding. However, there are some encodings that do not place XML infoset information (For example, tags for starting and ending XML elements) together with the data contained within elements. For example, in the MTOM encoding, the message is split into multiple parts. One part contains the XML infoset, which may contain references to other parts for actual element contents. Since the XML infoset will normally be small compared to the streamed contents, it makes sense to buffer the infoset, write it out, and then write the contents in a streamed way. This means that by the time the closing element tag is written, we should not have written out the stream yet.
For this purpose, the IStreamProvider interface is used. The interface has a GetStream method that returns the stream to be written. The correct way to write out a streamed message body in OnWriteBodyContents is as follows:
Write any necessary information preceding the stream (For example, the opening XML tag)
Call the WriteValue overload on the XmlDictionaryWriter that takes an IStreamProvider, with an IStreamProvider implementation that returns the stream to be written.
Write any information following the stream (For example, the closing XML tag)
With this approach, the XML writer has a choice of when to call GetStream and write out the streamed data. For example, the textual and binary XML writers will call it immediately and write out the streamed contents in between the start and end tags. The MTOM writer may decide to call GetStream later, when it is ready to write the appropriate part of the message.
Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter EditionThe Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.