HttpTransportBindingElement 类

定义

表示用于指定 HTTP 传输以传输消息的绑定元素。Represents the binding element used to specify an HTTP transport for transmitting messages.

public ref class HttpTransportBindingElement : System::ServiceModel::Channels::TransportBindingElement, System::ServiceModel::Description::IPolicyExportExtension, System::ServiceModel::Description::IWsdlExportExtension
public class HttpTransportBindingElement : System.ServiceModel.Channels.TransportBindingElement, System.ServiceModel.Description.IPolicyExportExtension, System.ServiceModel.Description.IWsdlExportExtension
type HttpTransportBindingElement = class
    inherit TransportBindingElement
    interface IPolicyExportExtension
    interface IWsdlExportExtension
Public Class HttpTransportBindingElement
Inherits TransportBindingElement
Implements IPolicyExportExtension, IWsdlExportExtension
继承
HttpTransportBindingElement
派生
实现

示例

下面的代码演示如何以命令性方式使用 HttpTransportBindingElementThe 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,如以下配置所示。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>  

注解

HttpTransportBindingElement 类是创建实现 HTTP 传输协议的自定义绑定的起始点。The HttpTransportBindingElement class is the starting point for creating a custom binding that implements the HTTP transport protocol. HTTP 是用于互操作性用途的主要传输。HTTP is the primary transport used for interoperability purposes. Windows Communication Foundation (WCF)支持此传输以确保与其他非 WCF Web 服务堆栈的互操作性。This transport is supported by Windows Communication Foundation (WCF) to ensure interoperability with other non-WCF Web services stacks.

WCF 服务模型使用此类创建实现 IChannelFactoryIChannelListener 接口的工厂对象。The WCF service model uses this class to create factory objects that implement the IChannelFactory and IChannelListener interfaces. 这些工厂对象反过来创建使用 HTTP 协议传输 SOAP 消息的通道和侦听器。These factory objects, in turn, create the channels and listeners that transmit SOAP messages using the HTTP protocol.

您可以通过设置此类的属性来配置此类创建的工厂,例如:AuthenticationSchemeHostNameComparisonModeMaxBufferSizeYou configure the factories that this class creates by setting its properties, such as AuthenticationScheme, HostNameComparisonMode, and MaxBufferSize.

您还可以设置基类 TransportBindingElement 上的属性,例如:ManualAddressingMaxReceivedMessageSizeMaxBufferPoolSizeYou can also set properties on the base class, TransportBindingElement, such as ManualAddressing, MaxReceivedMessageSize, and MaxBufferPoolSize. 有关完整的属性列表,请参见 TransportBindingElementFor a complete list of properties, see TransportBindingElement.

构造函数

HttpTransportBindingElement()

初始化 HttpTransportBindingElement 类的新实例。Initializes a new instance of the HttpTransportBindingElement class.

HttpTransportBindingElement(HttpTransportBindingElement)

初始化使用另一个绑定元素的 HttpTransportBindingElement 类的新实例。Initializes a new instance of the HttpTransportBindingElement class using another binding element.

属性

AllowCookies

获取或设置一个值,该值指示客户端是否接受 Cookie 并根据今后的请求传播 Cookie。Gets or sets a value that indicates whether the client accepts cookies and propagates them on future requests.

AuthenticationScheme

获取或设置身份验证方案,该方案用于验证 HTTP 侦听器所处理的客户端请求。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

获取或设置一个值,该值指示在对 URI 进行匹配时,是否使用主机名来访问服务。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.

LegacyExtendedProtectionPolicy
ManualAddressing

获取或设置一个值,该值指示是否要求对消息进行手动寻址。Gets or sets a value that indicates whether manual addressing of the message is required.

(继承自 TransportBindingElement)
MaxBufferPoolSize

获取或设置传输消息使用的任何缓冲池的最大字节大小。Gets or sets the maximum size, in bytes, of any buffer pools used by the transport.

(继承自 TransportBindingElement)
MaxBufferSize

获取或设置要使用的缓冲区的最大大小。Gets or sets the maximum size of the buffer to use. 对于缓冲的消息,此值与 MaxReceivedMessageSize 相同。For buffered messages this value is the same as MaxReceivedMessageSize. 对于经过流处理的消息,此值为必须以缓冲模式读取的 SOAP 标头的最大大小。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.

(继承自 TransportBindingElement)
MessageHandlerFactory

获取或设置 Http 传输消息处理程序工厂。Gets or sets the Http transport message handler factory.

ProxyAddress

获取或设置一个 URI,包含要用于 HTTP 请求的代理地址。Gets or sets a URI that contains the address of the proxy to use for HTTP requests.

ProxyAuthenticationScheme

获取或设置用于对 HTTP 代理所处理的客户端请求进行身份验证的身份验证方案。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

获取传输的 URI 方案。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. 如果启用,将对每个 TCP 连接执行一次 NTLM 身份验证。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

获取或设置绑定元素的 Web 套接配置。Gets or sets the web socket configuration of the binding element.

方法

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.

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.

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.

(继承自 Object)
GetHashCode()

用作默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetProperty<T>(BindingContext)

从指定的 BindingContext 获取属性。Gets a property from the specified BindingContext.

GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
ShouldSerializeExtendedProtectionPolicy()

返回一个表明不可能对扩展保护策略进行 XAML 序列化的值。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()

确定web套接设置是否应序列化。Determines whether the web socket settings should be serialized.

ToString()

返回一个表示当前对象的 string。Returns a string that represents the current object.

(继承自 Object)
UpdateAuthenticationSchemes(BindingContext)

更新包含绑定上下文的传输身份验证方案。Updates the transport authentication schemes that contains the binding context.

显式接口实现

IPolicyExportExtension.ExportPolicy(MetadataExporter, PolicyConversionContext)

导出有关绑定的自定义策略断言。Exports a custom policy assertion about bindings.

IWsdlExportExtension.ExportContract(WsdlExporter, WsdlContractConversionContext)

为协定将自定义 Web 服务描述语言 (WSDL) 元素写入到生成的 WSDL 中。Writes custom Web Services Description Language (WSDL) elements into the generated WSDL for a contract.

IWsdlExportExtension.ExportEndpoint(WsdlExporter, WsdlEndpointConversionContext)

为终结点将自定义 Web 服务描述语言 (WSDL) 元素写入到生成的 WSDL 中。Writes custom Web Services Description Language (WSDL) elements into the generated WSDL for an endpoint.

适用于