Редагувати

Поділитися через


HttpTransportBindingElement Class

Definition

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

public ref class HttpTransportBindingElement : System::ServiceModel::Channels::TransportBindingElement
public ref class HttpTransportBindingElement : System::ServiceModel::Channels::TransportBindingElement, System::ServiceModel::Description::IPolicyExportExtension, System::ServiceModel::Description::IWsdlExportExtension
public class HttpTransportBindingElement : System.ServiceModel.Channels.TransportBindingElement
public class HttpTransportBindingElement : System.ServiceModel.Channels.TransportBindingElement, System.ServiceModel.Description.IPolicyExportExtension, System.ServiceModel.Description.IWsdlExportExtension
type HttpTransportBindingElement = class
    inherit TransportBindingElement
type HttpTransportBindingElement = class
    inherit TransportBindingElement
    interface IWsdlExportExtension
    interface IPolicyExportExtension
Public Class HttpTransportBindingElement
Inherits TransportBindingElement
Public Class HttpTransportBindingElement
Inherits TransportBindingElement
Implements IPolicyExportExtension, IWsdlExportExtension
Inheritance
HttpTransportBindingElement
Derived
Implements

Examples

The following code shows how to imperatively use the HttpTransportBindingElement.

Uri baseAddress = new Uri("http://localhost:8000/servicemodelsamples/service");

// Create a ServiceHost for the CalculatorService type and provide the base address.
using (ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService), baseAddress))
{
    // Create a custom binding that contains two binding elements.
    ReliableSessionBindingElement reliableSession = new ReliableSessionBindingElement();
    reliableSession.Ordered = true;

    HttpTransportBindingElement httpTransport = new HttpTransportBindingElement();
    httpTransport.AuthenticationScheme = System.Net.AuthenticationSchemes.Anonymous;
    httpTransport.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;

    CustomBinding binding = new CustomBinding(reliableSession, httpTransport);

    // Add an endpoint using that binding.
    serviceHost.AddServiceEndpoint(typeof(ICalculator), binding, "");

    // Add a MEX endpoint.
    ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
    smb.HttpGetEnabled = true;
    smb.HttpGetUrl = new Uri("http://localhost:8001/servicemodelsamples");
    serviceHost.Description.Behaviors.Add(smb);

    // Open the ServiceHostBase to create listeners and start listening for messages.
    serviceHost.Open();

    // The service can now be accessed.
    Console.WriteLine("The service is ready.");
    Console.WriteLine("Press <ENTER> to terminate service.");
    Console.WriteLine();
    Console.ReadLine();

    // Close the ServiceHostBase to shutdown the service.
    serviceHost.Close();
}
Dim baseAddress As New Uri("http://localhost:8000/servicemodelsamples/service")

' Create a ServiceHost for the CalculatorService type and provide the base address.
Using serviceHost As New ServiceHost(GetType(CalculatorService), baseAddress)
    ' Create a custom binding that contains two binding elements.
    Dim reliableSession As New ReliableSessionBindingElement()
    reliableSession.Ordered = True

    Dim httpTransport As New HttpTransportBindingElement()
    httpTransport.AuthenticationScheme = System.Net.AuthenticationSchemes.Anonymous
    httpTransport.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard

    Dim binding As New CustomBinding(reliableSession, httpTransport)

    ' Add an endpoint using that binding.
    serviceHost.AddServiceEndpoint(GetType(ICalculator), binding, "")

    ' Add a MEX endpoint.
    Dim smb As New ServiceMetadataBehavior()
    smb.HttpGetEnabled = True
    smb.HttpGetUrl = New Uri("http://localhost:8001/servicemodelsamples")
    serviceHost.Description.Behaviors.Add(smb)

    ' Open the ServiceHostBase to create listeners and start listening for messages.
    serviceHost.Open()

    ' The service can now be accessed.
    Console.WriteLine("The service is ready.")
    Console.WriteLine("Press <ENTER> to terminate service.")
    Console.WriteLine()
    Console.ReadLine()

    ' Close the ServiceHostBase to shutdown the service.
    serviceHost.Close()
End Using

HttpTransportBindingElement can also be used in a configuration file as shown in the following configuration.

<bindings>  
  <customBinding>  
    <binding name="Binding1">  
      <reliableSession acknowledgementInterval="00:00:00.2000000" enableFlowControl="true"  
                        maxTransferWindowSize="32" inactivityTimeout="00:10:00" maxPendingChannels="128"  
                        maxRetryCount="8" ordered="true" />  
      <security mode="None"/>  
      <httpTransport authenticationScheme="Anonymous" bypassProxyOnLocal="false"  
                    hostNameComparisonMode="StrongWildcard"   
                    proxyAuthenticationScheme="Anonymous" realm=""   
                    useDefaultWebProxy="true" />  
    </binding>  
  </customBinding>  
</bindings>  

Remarks

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. This transport is supported by Windows Communication Foundation (WCF) to ensure interoperability with other non-WCF Web services stacks.

The WCF service model uses this class to create factory objects that implement the IChannelFactory and IChannelListener interfaces. These factory objects, in turn, create the channels and listeners that transmit SOAP messages using the HTTP protocol.

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

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

Constructors

HttpTransportBindingElement()

Initializes a new instance of the HttpTransportBindingElement class.

HttpTransportBindingElement(HttpTransportBindingElement)

Initializes a new instance of the HttpTransportBindingElement class using another binding element.

Properties

AllowCookies

Gets or sets a value that indicates whether the client accepts cookies and propagates them on future requests.

AuthenticationScheme

Gets or sets the authentication scheme used to authenticate client requests being processed by an HTTP listener.

BypassProxyOnLocal

Gets or sets a value that indicates whether proxies are ignored for local addresses.

DecompressionEnabled

Gets or sets whether the process for returning compressed message data to its original size and format is enabled.

ExtendedProtectionPolicy

Gets or sets the value of the extended security policy used by the server to validate incoming client connections.

HostNameComparisonMode

Gets or sets a value that indicates whether the hostname is used to reach the service when matching on the URI.

KeepAliveEnabled

Gets or sets a value that indicates whether to make a persistent connection to a service endpoint.

ManualAddressing

Gets or sets a value that indicates whether manual addressing of the message is required.

(Inherited from TransportBindingElement)
MaxBufferPoolSize

Gets or sets the maximum size, in bytes, of any buffer pools used by the transport.

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

MaxPendingAccepts

Gets or sets the maximum number of connections the service can accept simultaneously.

MaxReceivedMessageSize

Gets or sets the maximum allowable message size, in bytes, that can be received.

(Inherited from TransportBindingElement)
MessageHandlerFactory

Gets or sets the Http transport message handler factory.

Proxy
ProxyAddress

Gets or sets a URI that contains the address of the proxy to use for HTTP requests.

ProxyAuthenticationScheme

Gets or sets the authentication scheme used to authenticate client requests being processed by an HTTP proxy.

Realm

Gets or sets the authentication realm.

RequestInitializationTimeout

Gets or sets the requested initialization time out.

Scheme

Gets the URI scheme for the transport.

TransferMode

Gets or sets the transfer mode.

UnsafeConnectionNtlmAuthentication

Gets or sets a value that indicates whether Unsafe Connection Sharing is enabled on the server. If enabled, NTLM authentication is performed once on each TCP connection.

UseDefaultWebProxy

Gets or sets a value that indicates whether the machine-wide proxy settings are used rather than the user specific settings.

WebSocketSettings

Gets or sets the web socket configuration of the binding element.

Methods

BuildChannelFactory<TChannel>(BindingContext)

Creates a channel factory that can be used to create a channel.

BuildChannelListener<TChannel>(BindingContext)

Creates a channel listener of the specified type.

BuildChannelListener<TChannel>(BindingContext)

Initializes a channel listener to accept channels of a specified type from the binding context.

(Inherited from BindingElement)
CanBuildChannelFactory<TChannel>(BindingContext)

Determines whether a channel factory of the specified type can be built.

CanBuildChannelListener<TChannel>(BindingContext)

Determines whether a channel listener of the specified type can be built.

CanBuildChannelListener<TChannel>(BindingContext)

Returns a value that indicates whether the binding element can build a listener for a specific type of channel.

(Inherited from BindingElement)
Clone()

Creates a new instance that is a copy of the current binding element.

Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetProperty<T>(BindingContext)

Gets a property from the specified BindingContext.

GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
ShouldSerializeExtendedProtectionPolicy()

Returns a valueindicating that it is not possible to XAML serialize the extended protection policy.

ShouldSerializeMessageHandlerFactory()

Determines whether the message handler factory should be serialized.

ShouldSerializeWebSocketSettings()

Determines whether the web socket settings should be serialized.

ToString()

Returns a string that represents the current object.

(Inherited from Object)
UpdateAuthenticationSchemes(BindingContext)

Updates the transport authentication schemes that contains the binding context.

Explicit Interface Implementations

IPolicyExportExtension.ExportPolicy(MetadataExporter, PolicyConversionContext)

Exports a custom policy assertion about bindings.

IWsdlExportExtension.ExportContract(WsdlExporter, WsdlContractConversionContext)

Writes custom Web Services Description Language (WSDL) elements into the generated WSDL for a contract.

IWsdlExportExtension.ExportEndpoint(WsdlExporter, WsdlEndpointConversionContext)

Writes custom Web Services Description Language (WSDL) elements into the generated WSDL for an endpoint.

Applies to