BinaryMessageEncodingBindingElement Constructor
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Initializes a new instance of the BinaryMessageEncodingBindingElement class.
Assembly: System.ServiceModel (in System.ServiceModel.dll)
' 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 PhoneApplicationPage '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
Show: