HttpTransportBindingElement Class
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Represents the binding element used to specify an HTTP transport for transmitting messages.
System.ServiceModel.Channels.BindingElement
System.ServiceModel.Channels.TransportBindingElement
System.ServiceModel.Channels.HttpTransportBindingElement
System.ServiceModel.Channels.HttpsTransportBindingElement
Assembly: System.ServiceModel (in System.ServiceModel.dll)
The HttpTransportBindingElement type exposes the following members.
| Name | Description | |
|---|---|---|
![]() | HttpTransportBindingElement() | Initializes a new instance of the HttpTransportBindingElement class. |
![]() | HttpTransportBindingElement(HttpTransportBindingElement) | Initializes a new instance of the HttpTransportBindingElement class. |
| Name | Description | |
|---|---|---|
![]() | ManualAddressing | Gets or sets a value that indicates whether manual addressing of the message is required. (Inherited from TransportBindingElement.) |
![]() | MaxBufferSize | Gets 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. |
![]() | MaxReceivedMessageSize | Gets and sets the maximum allowable message size that can be received. (Inherited from TransportBindingElement.) |
![]() | Scheme | Gets the URI scheme for the transport. (Overrides TransportBindingElement.Scheme.) |
| Name | Description | |
|---|---|---|
![]() | BuildChannelFactory<TChannel> | Creates a channel factory that can be used to create a channel. (Overrides BindingElement.BuildChannelFactory<TChannel>(BindingContext).) |
![]() | CanBuildChannelFactory<TChannel> | Determines whether a channel factory of the specified type can be built. (Overrides BindingElement.CanBuildChannelFactory<TChannel>(BindingContext).) |
![]() | Clone | Creates a copy of the current binding element. (Overrides BindingElement.Clone().) |
![]() | Equals(Object) | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) |
![]() | Finalize | Allows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.) |
![]() | GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) |
![]() | GetProperty<T> | Gets a property from the specified BindingContext. (Overrides TransportBindingElement.GetProperty<T>(BindingContext).) |
![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() | MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) |
![]() | ToString | Returns a string that represents the current object. (Inherited from Object.) |
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 Windows Phone 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.
public partial class MainPage : PhoneApplicationPage
{
//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 transport and binary message encoding.
var elements = new List<BindingElement>();
elements.Add(new BinaryMessageEncodingBindingElement());
// Create an instance of the HttpTransportBindingElement
HttpTransportBindingElement httpTransportBindingElement = new HttpTransportBindingElement();
string txtDefaultMaxBufferSize = httpTransportBindingElement.MaxBufferSize.ToString();
txtOutput1.Text = txtDefaultMaxBufferSize; //The value is 65536 (0x10000).
// Change the maximum buffer size.
httpTransportBindingElement.MaxBufferSize = 0x20000;
string txtNewMaxBufferSize = httpTransportBindingElement.MaxBufferSize.ToString();
txtOutput2.Text = txtNewMaxBufferSize; //The value is 131072 (0x20000).
// Output http scheme.
string txtScheme = httpTransportBindingElement.Scheme;
txtOutput5.Text = txtScheme; //The value is http.
elements.Add(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;
}


