Export (0) Print
Expand All

BinaryMessageEncodingBindingElement Class

The binding element that specifies the .NET Binary Format for XML used to encode messages.

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

'Declaration
Public NotInheritable Class BinaryMessageEncodingBindingElement _
	Inherits MessageEncodingBindingElement

The BinaryMessageEncodingBindingElement type exposes the following members.

  NameDescription
Public methodSupported by Silverlight for Windows PhoneBinaryMessageEncodingBindingElementInitializes a new instance of the BinaryMessageEncodingBindingElement class.
Top

  NameDescription
Public propertySupported by Silverlight for Windows PhoneMessageVersionGets or sets the SOAP message and WS-Addressing versions that are used or expected. (Overrides MessageEncodingBindingElement.MessageVersion.)
Top

  NameDescription
Public methodSupported by Silverlight for Windows PhoneBuildChannelFactory(Of TChannel)Builds the channel factory stack on the client that creates a specified type of channel for a specified context. (Overrides BindingElement.BuildChannelFactory(Of TChannel)(BindingContext).)
Public methodSupported by Silverlight for Windows PhoneCanBuildChannelFactory(Of 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 BinaryMessageEncodingBindingElement object initialized from the current one. (Overrides BindingElement.Clone.)
Public methodSupported by Silverlight for Windows PhoneCreateMessageEncoderFactoryCreates a factory for binary 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 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(Of T)Returns the typed object requested, if present, from the appropriate layer in the channel stack. (Inherited from MessageEncodingBindingElement.)
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 includes two types of encoding for SOAP messages: Text and Binary.

The BinaryMessageEncodingBindingElement is the binding element that specified the .NET Binary Format for XML should be used for encoding messages, and has options to specify the character encoding and the SOAP and WS-Addressing version to be used. Binary encoding is the most efficient but least interoperable of the encoding options.

For more information about

the binding element that specifies messages are encoded using a textual representation of XML, see TextMessageEncodingBindingElement.

To implement a custom message encoder, use the MessageEncodingBindingElement class.


	' This is an example of how to create a custom binding with a specified encoding and tansport,
	' and how to create and open a channel for the service endpoint configured with the custom binding.
	Partial Public Class MainPage
		Inherits UserControl
		'Declare a separate UI thread.
		Private uiThread As SynchronizationContext

		Public Sub New()
			InitializeComponent()
		End Sub

		Private Sub Button_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)

			'Create a custom binding that uses HTTP and binary message encoding.
			Dim elements = New List(Of BindingElement)()
			elements.Add(New BinaryMessageEncodingBindingElement())
			elements.Add(New HttpTransportBindingElement())
			Dim binding = New CustomBinding(elements)

			'Create a channel factory for the service endpoint configured with the custom binding.
			Dim cf = New ChannelFactory(Of IService1)(binding, New EndpointAddress("http://localhost:10483/Service1.svc"))


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

			'Open the channel.
			Dim channel As IService1 = cf.CreateChannel()

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

		End Sub

		'Implement the callback. 
		Private Sub GetPersonCallback(ByVal asyncResult As IAsyncResult)
			Dim p As Person = (CType(asyncResult.AsyncState, IService1)).EndGetPerson(asyncResult)

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

		End Sub

		'Update the result displayed for the GetPerson invocation.
		Private Sub UpdateUI(ByVal state As Object)
			Dim p As Person = CType(state, Person)
			resultPersonName.Text = "The name of the Person is: " & p.Name
			resultPersonAge.Text = "The age of the Person is: " & p.Age
		End Sub



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

ADD
Show:
© 2014 Microsoft