This topic has not yet been rated - Rate this topic

ByteStreamMessageEncodingBindingElement Class

The binding element that specifies the message encoding as a stream of bytes and has the option to specify the character encoding.

System.Object
  System.ServiceModel.Channels.BindingElement
    System.ServiceModel.Channels.MessageEncodingBindingElement
      System.ServiceModel.Channels.ByteStreamMessageEncodingBindingElement

Namespace:  System.ServiceModel.Channels
Assembly:  System.ServiceModel.Channels (in System.ServiceModel.Channels.dll)
public sealed class ByteStreamMessageEncodingBindingElement : MessageEncodingBindingElement

The ByteStreamMessageEncodingBindingElement type exposes the following members.

  Name Description
Public method ByteStreamMessageEncodingBindingElement() Initializes a new instance of the ByteStreamMessageEncodingBindingElement class.
Public method ByteStreamMessageEncodingBindingElement(XmlDictionaryReaderQuotas) Initializes a new instance of the ByteStreamMessageEncodingBindingElement class with the specified quota.
Top
  Name Description
Public property MessageVersion Gets or sets the SOAP message and WS-Addressing versions that are used or expected. (Overrides MessageEncodingBindingElement.MessageVersion.)
Public property ReaderQuotas Gets or sets constraints on the complexity of XML messages that can be processed by endpoints configured with this binding element.
Top
  Name Description
Public method BuildChannelFactory<TChannel> Builds the channel factory stack on the client that creates a specified type of channel for a specified context. (Overrides BindingElement.BuildChannelFactory<TChannel>(BindingContext).)
Public method BuildChannelListener<TChannel> Builds the channel listener on the service that accepts a specified type of channel for a specified context. (Overrides BindingElement.BuildChannelListener<TChannel>(BindingContext).)
Public method CanBuildChannelFactory<TChannel> Returns a value that indicates whether the current binding can build a factory for a specified type of channel and context. (Overrides BindingElement.CanBuildChannelFactory<TChannel>(BindingContext).)
Public method CanBuildChannelListener<TChannel> Returns a value that indicates whether the current binding can build a listener for a specified type of channel and context. (Overrides BindingElement.CanBuildChannelListener<TChannel>(BindingContext).)
Public method Clone Creates a new ByteStreamMessageEncodingBindingElement object initialized from the current one. (Overrides BindingElement.Clone().)
Public method CreateMessageEncoderFactory Creates a factory for byte stream message encoders that employ the SOAP and WS-Addressing versions and the character encoding specified by the current encoding binding element. (Overrides MessageEncodingBindingElement.CreateMessageEncoderFactory().)
Public method Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetProperty<T> Returns the typed object requested, if present, from the appropriate layer in the channel stack. (Inherited from MessageEncodingBindingElement.)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public method ShouldSerializeMessageVersion Returns a value that indicates whether the MessageVersion property has changed from its default value and should be serialized.
Public method ShouldSerializeReaderQuotas Returns a value that indicates whether the ReaderQuotas property has changed from its default value and should be serialized.
Public method ToString Returns a string that represents the current object. (Inherited from Object.)
Top

.NET Framework

Supported in: 4

.NET Framework Client Profile

Supported in: 4

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
Sample
Below link will point you to a sample:
http://msdn.microsoft.com/en-us/library/ee960169(VS.100).aspx
WCF Code Sample

Here's a sample showing three different WCF MessageEncoders and what their serialized output looks like:

    class Program
    {
        static void Main(string[] args)
        {
            MessageEncodingBindingElement[] encodings = new MessageEncodingBindingElement[]
            {
                new TextMessageEncodingBindingElement() { MessageVersion = MessageVersion.None },
                new BinaryMessageEncodingBindingElement(),
                new ByteStreamMessageEncodingBindingElement() { MessageVersion = MessageVersion.None },
            };
            foreach (MessageEncodingBindingElement encoding in encodings)
            {
                Console.WriteLine("==============================");
                Console.WriteLine("{0}", encoding.GetType().Name);
                Console.WriteLine("==============================");
                MessageEncoderFactory encoderFactory = encoding.CreateMessageEncoderFactory();
                byte[] data = new byte[32];
                for (int i = 0; i < data.Length; i++)
                {
                    data[i] = unchecked((byte)i);
                }
                XElement xml = new XElement("Binary", new XBinary(new ArraySegment<byte>(data)));
                Message message = Message.CreateMessage(encoding.MessageVersion, string.Empty, xml);
                MemoryStream stream = new MemoryStream();
                encoderFactory.Encoder.WriteMessage(message, stream);
                stream.Flush();
                stream.Position = 0;
                int length = checked((int)stream.Length);
                byte[] buffer = stream.GetBuffer();
                StringBuilder sb = new StringBuilder(length * 2);
                for (int i = 0; i < length; i++)
                {
                    sb.AppendFormat("{0:X2} ", buffer[i]);
                }
                Console.WriteLine("Original Message.ToString():\r\n{0}", message);
                Console.WriteLine("Serialized Message is {0} bytes long", length);
                Console.WriteLine("Payload:\r\n{0}\r\n", sb);
            }
        }
    }
    class XBinary : XText
    {
        ArraySegment<byte> buffer;
        public XBinary(ArraySegment<byte> buffer)
            : base(string.Empty)
        {
            this.buffer = buffer;
        }
        public override void WriteTo(XmlWriter writer)
        {
            writer.WriteBase64(this.buffer.Array, this.buffer.Offset, this.buffer.Count);
        }
    }

Output:

Original Message:
<Binary>AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8=</Binary>
==============================
TextMessageEncodingBindingElement
==============================
Serialized Message is 61 bytes long
Payload:
3C 42 69 6E 61 72 79 3E 41 41 45 43 41 77 51 46 42 67 63 49 43 51 6F 4C 44 41 30
 4F 44 78 41 52 45 68 4D 55 46 52 59 58 47 42 6B 61 47 78 77 64 48 68 38 3D 3C 2
F 42 69 6E 61 72 79 3E
==============================
BinaryMessageEncodingBindingElement
==============================
Serialized Message is 67 bytes long
Payload:
56 02 0B 01 73 04 0B 01 61 06 56 08 44 0A 1E 00 82 01 01 56 0E 40 06 42 69 6E 61
 72 79 9E 1E 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11 12 13 14 15 1
6 17 18 19 1A 1B 1C 1D 9F 02 1E 1F 01 01
==============================
ByteStreamMessageEncodingBindingElement
==============================
Serialized Message is 32 bytes long
Payload:
00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11 12 13 14 15 16 17 18 19 1A
 1B 1C 1D 1E 1F