Export (0) Print
Expand All

HttpTransportBindingElement Class

Represents the binding element used to specify an HTTP transport for transmitting messages.

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

'Declaration
Public Class HttpTransportBindingElement _
	Inherits TransportBindingElement

The HttpTransportBindingElement type exposes the following members.

  NameDescription
Public methodSupported by Silverlight for Windows PhoneHttpTransportBindingElementInitializes a new instance of the HttpTransportBindingElement class.
Protected methodSupported by Silverlight for Windows PhoneHttpTransportBindingElement(HttpTransportBindingElement)Initializes a new instance of the HttpTransportBindingElement class.
Top

  NameDescription
Public propertySupported by Silverlight for Windows PhoneManualAddressingGets or sets a value that indicates whether manual addressing of the message is required. (Inherited from TransportBindingElement.)
Public propertySupported by Silverlight for Windows PhoneMaxBufferSizeGets or sets the maximum size of the buffer to use. For buffered messages this value is the same as MaxReceivedMessageSize. For streamed messages, this value is the maximum size of the SOAP headers, which must be read in buffered mode.
Public propertySupported by Silverlight for Windows PhoneMaxReceivedMessageSizeGets and sets the maximum allowable message size that can be received. (Inherited from TransportBindingElement.)
Public propertySupported by Silverlight for Windows PhoneSchemeGets the URI scheme for the transport. (Overrides TransportBindingElement.Scheme.)
Public propertyTransferModeGets or sets a value that indicates whether messages are sent buffered or streamed.
Top

  NameDescription
Public methodSupported by Silverlight for Windows PhoneBuildChannelFactory(Of TChannel)Creates a channel factory that can be used to create a channel. (Overrides BindingElement.BuildChannelFactory(Of TChannel)(BindingContext).)
Public methodSupported by Silverlight for Windows PhoneCanBuildChannelFactory(Of TChannel)Determines whether a channel factory of the specified type can be built. (Overrides BindingElement.CanBuildChannelFactory(Of TChannel)(BindingContext).)
Public methodSupported by Silverlight for Windows PhoneCloneCreates a copy of the current binding element. (Overrides BindingElement.Clone.)
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)Gets a property from the specified BindingContext. (Overrides TransportBindingElement.GetProperty(Of 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

The HttpTransportBindingElement class is the starting point for creating a custom binding that implements the HTTP transport protocol. HTTP is the primary transport used for interoperability purposes.

The Silverlight 5 service model uses this class to create factory objects that implement the IChannelFactory interface. These factory objects in turn create the channels that transmit SOAP messages using the HTTP protocol.

You configure the factories that this class creates by setting its properties, such as MaxBufferSize.

You can also set properties on the base class, TransportBindingElement, such as MaxReceivedMessageSize and ManualAddressing. For a complete list of properties, see TransportBindingElement.


	' This is an example of how to create a custom binding with a specified encoding and HTTP 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 transport and binary message encoding.
			Dim elements = New List(Of BindingElement)()
			elements.Add(New BinaryMessageEncodingBindingElement())

			' Create an instance of the HttpTransportBindingElement
			Dim httpTransportBindingElement As New HttpTransportBindingElement()
			Dim txtDefaultMaxBufferSize As String = httpTransportBindingElement.MaxBufferSize.ToString()
			txtOutput1.Text = txtDefaultMaxBufferSize 'The value is 65536 (0x10000).

			' Change the maximum buffer size.
			httpTransportBindingElement.MaxBufferSize = &H20000
			Dim txtNewMaxBufferSize As String = httpTransportBindingElement.MaxBufferSize.ToString()
			txtOutput2.Text = txtNewMaxBufferSize 'The value is 131072 (0x20000).

			' Output http scheme.
			Dim txtScheme As String = httpTransportBindingElement.Scheme
			txtOutput5.Text = txtScheme 'The value is http.

			elements.Add(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