Export (0) Print
Expand All

TextMessageEncodingBindingElement Class

The binding element that specifies the character encoding and message versioning used for text-based SOAP messages.

Namespace:  System.ServiceModel.Channels
Assembly:  System.ServiceModel (in System.ServiceModel.dll)

public sealed class TextMessageEncodingBindingElement : MessageEncodingBindingElement

The TextMessageEncodingBindingElement type exposes the following members.

  NameDescription
Public methodSupported by Silverlight for Windows PhoneTextMessageEncodingBindingElement()Initializes a new instance of the TextMessageEncodingBindingElement class.
Public methodSupported by Silverlight for Windows PhoneTextMessageEncodingBindingElement(MessageVersion, Encoding)Initializes a new instance of the TextMessageEncodingBindingElement class with a specified message version and encoding.
Top

  NameDescription
Public propertySupported by Silverlight for Windows PhoneMessageVersionGets or sets the SOAP and WS-Addressing versions that are used to format the text message. (Overrides MessageEncodingBindingElement.MessageVersion.)
Public propertySupported by Silverlight for Windows PhoneWriteEncodingGets or sets the encoding that is used to format the characters in the text message.
Top

  NameDescription
Public methodSupported by Silverlight for Windows PhoneBuildChannelFactory<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 methodSupported by Silverlight for Windows PhoneCanBuildChannelFactory<TChannel>Returns a value that indicates whether the binding element can build a channel factory for a specific type of channel. (Inherited from BindingElement.)
Public methodSupported by Silverlight for Windows PhoneCloneCreates a new TextMessageEncodingBindingElement object initialized from the current one. (Overrides BindingElement.Clone().)
Public methodSupported by Silverlight for Windows PhoneCreateMessageEncoderFactoryCreates a factory for text message encoders that employs the message version and character encoding specified by the current encoding binding element. (Overrides MessageEncodingBindingElement.CreateMessageEncoderFactory().)
Public methodSupported by Silverlight for Windows PhoneEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodSupported by Silverlight for Windows PhoneFinalizeAllows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public methodSupported by Silverlight for Windows PhoneGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodSupported by Silverlight for Windows PhoneGetProperty<T>Returns the typed object requested, if present, from the appropriate layer in the channel stack. (Inherited from MessageEncodingBindingElement.)

In Silverlight for Windows Phone, this member is overridden by GetProperty<T>(BindingContext).


In XNA Framework, this member is overridden by GetProperty<T>(BindingContext).
Public methodSupported by Silverlight for Windows PhoneGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodSupported by Silverlight for Windows PhoneMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodSupported by Silverlight for Windows PhoneToStringReturns a string that represents the current object. (Inherited from Object.)
Top

Encoding is the process of transforming a message into a sequence of bytes. Decoding is the reverse process. Silverlight 5 uses Text encoding for SOAP messages.

The text encoding represented by the TextMessageEncodingBindingElement is the most interoperable, but the least efficient encoder for XML messages. Web service or Web service client can generally understand textual XML. However, transmitting large blocks of binary data as text is not efficient.

For more information about

how to implement a custom message encoder, use the MessageEncodingBindingElement class.


    // This is an example of how to create a custom binding with a text encoding and HTTP tansport,
    // and how to create and open a channel for the service endpoint configured with the custom binding.
    public partial class MainPage : UserControl
    {
        //Declare a separate UI thread.
        SynchronizationContext uiThread;

        public MainPage()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {

            //Create a custom binding that uses HTTP and binary message encoding.
            var elements = new List<BindingElement>();
            elements.Add(new TextMessageEncodingBindingElement());
            elements.Add(new HttpTransportBindingElement());
            var binding = new CustomBinding(elements);

            //Create a channel factory for the service endpoint configured with the custom binding.
            var cf = new ChannelFactory<IService1>(binding, new EndpointAddress("http://localhost:10483/Service1.svc"));


            //Save the synchronized context for the UI thread.
            uiThread = SynchronizationContext.Current;

            //Open the channel.
            IService1 channel = cf.CreateChannel();

            //Invoke the GetPerson method on the service asynchronously. The signature is:
            //IAsyncResult BeginGetPerson(int personId, AsyncCallback callback, object state)
            channel.BeginGetPerson(4, GetPersonCallback, channel);

        }

        //Implement the callback. 
        void GetPersonCallback(IAsyncResult asyncResult)
        {
            Person p = ((IService1)asyncResult.AsyncState).EndGetPerson(asyncResult);

            //Update the UI thread and its output with the result of the method call.
            uiThread.Post(UpdateUI, p);

        }

        //Update the result displayed for the GetPerson invocation.
        private void UpdateUI(object state)
        {
            Person p = (Person)state;
            resultPersonName.Text = "The name of the Person is: " + p.Name;
            resultPersonAge.Text = "The age of the Person is: " + p.Age;
        }



Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Community Additions

Show:
© 2014 Microsoft