HttpTransportBindingElement 類別

定義

表示用來指定傳輸訊息之 HTTP 傳輸的繫結項目。

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
繼承
HttpTransportBindingElement
衍生
實作

範例

下列程式碼會示範如何強制使用 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 也可以在組態檔中使用,如下列組態所示。

<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 傳輸通訊協定的自訂繫結。 HTTP 是用於互通性目的的主要傳輸。 Windows Communication Foundation (WCF) 支援此傳輸,以確保與其他非 WCF Web 服務堆疊的互通性。

WCF 服務模型會使用此類別來建立實作 和 IChannelListener 介面的 IChannelFactory Factory 物件。 然後,這些處理站物件會建立使用 HTTP 通訊協定傳輸 SOAP 訊息的通道和接聽程式。

您可以設定這個類別的屬性,以設定其所建立的處理站,例如:AuthenticationSchemeHostNameComparisonModeMaxBufferSize

您也可以設定基底類別 TransportBindingElement 的屬性,例如:ManualAddressingMaxReceivedMessageSizeMaxBufferPoolSize。 如需完整的屬性清單,請參閱 TransportBindingElement

建構函式

HttpTransportBindingElement()

初始化 HttpTransportBindingElement 類別的新執行個體。

HttpTransportBindingElement(HttpTransportBindingElement)

使用另一個繫結項目,初始化 HttpTransportBindingElement 類別的新執行個體。

屬性

AllowCookies

取得或設定值,這個值會指出用戶端是否接受 Cookie 並依未來要求傳播 Cookie。

AuthenticationScheme

取得或設定驗證配置,用於驗證由 HTTP 接聽程式處理的用戶端要求。

BypassProxyOnLocal

取得或設定值,指出是否忽略本機位址的 Proxy。

DecompressionEnabled

取得或設定是否已啟用傳回壓縮訊息資料至其原始大小與格式的程序。

ExtendedProtectionPolicy

取得或設定值,這個值是伺服器用來驗證連入用戶端連線的延伸安全性原則。

HostNameComparisonMode

取得或設定值,這個值會指出在比對 URI 時主機名稱是否會用來取用服務。

KeepAliveEnabled

取得或設定值,這個值表示是否要與服務端點建立持續連線。

ManualAddressing

取得或設定值,這個值會指出是否需要訊息的手動定址。

(繼承來源 TransportBindingElement)
MaxBufferPoolSize

取得或設定傳輸所使用之任何緩衝區集區的大小上限 (以位元組為單位)。

(繼承來源 TransportBindingElement)
MaxBufferSize

取得或設定要使用之緩衝區的大小上限。 對於經過緩衝處理的訊息,這個值與 MaxReceivedMessageSize 相同。 對於已進行資料流處理的訊息,這個值為 SOAP 標頭的最大大小 (必須在緩衝模式中讀取)。

MaxPendingAccepts

取得或設定服務能夠同時接受的最大連線數。

MaxReceivedMessageSize

取得或設定可接收之可允許的訊息大小上限 (以位元組為單位)。

(繼承來源 TransportBindingElement)
MessageHandlerFactory

取得或設定 Http 傳輸訊息處理常式 factory。

Proxy

表示用來指定傳輸訊息之 HTTP 傳輸的繫結項目。

ProxyAddress

取得或設定 URI,包含用於 HTTP 要求的 Proxy 位址。

ProxyAuthenticationScheme

取得或設定驗證配置,用於驗證由 HTTP Proxy 處理的用戶端要求。

Realm

取得或設定驗證領域。

RequestInitializationTimeout

取得或設定要求的初始設定逾時。

Scheme

取得用於傳輸的 URI 配置。

TransferMode

取得或設定傳輸模式。

UnsafeConnectionNtlmAuthentication

取得或設定值,指出伺服器上是否啟用不安全的連線共用。 如果已啟用,NTLM 驗證會在各 TCP 連線上執行一次。

UseDefaultWebProxy

取得或設定值,指出是否使用全機器 Proxy 設定而非使用者特定設定。

WebSocketSettings

取得或設定繫結項目的 Web 通訊端組態。

方法

BuildChannelFactory<TChannel>(BindingContext)

建立可用來建立通道的通道處理站。

BuildChannelListener<TChannel>(BindingContext)

建立指定型別的通道接聽程式。

BuildChannelListener<TChannel>(BindingContext)

初始化通道接聽項,以便從繫結內容接受指定之類型的通道。

(繼承來源 BindingElement)
CanBuildChannelFactory<TChannel>(BindingContext)

判斷是否可以建置指定之型別的通道處理站。

CanBuildChannelListener<TChannel>(BindingContext)

判斷是否可以建置指定之型別的通道接聽項。

CanBuildChannelListener<TChannel>(BindingContext)

傳回值,指出繫結項目是否可以建置特定通道型別的通道接聽程式。

(繼承來源 BindingElement)
Clone()

建立目前繫結項目複本的新執行個體。

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetProperty<T>(BindingContext)

從指定的 BindingContext 中取得屬性。

GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ShouldSerializeExtendedProtectionPolicy()

傳回值,這個值指出不可能讓 XAML 序列化延伸保護原則。

ShouldSerializeMessageHandlerFactory()

判斷是否應將息處理常式 Factory 序列化。

ShouldSerializeWebSocketSettings()

判斷是否應將 Web 通訊端設定序列化。

ToString()

傳回代表目前物件的字串。

(繼承來源 Object)
UpdateAuthenticationSchemes(BindingContext)

更新包含繫結內容的傳輸驗證配置。

明確介面實作

IPolicyExportExtension.ExportPolicy(MetadataExporter, PolicyConversionContext)

匯出關於繫結的自訂原則判斷提示。

IWsdlExportExtension.ExportContract(WsdlExporter, WsdlContractConversionContext)

將自訂的 Web 服務描述語言 (WSDL) 項目寫入為合約產生的 WSDL。

IWsdlExportExtension.ExportEndpoint(WsdlExporter, WsdlEndpointConversionContext)

將自訂的 Web 服務描述語言 (WSDL) 項目寫入為端點產生的 WSDL。

適用於