HttpTransportBindingElement 類別
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
表示用來指定傳輸訊息之 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。
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 訊息的通道和接聽程式。
您可以設定這個類別的屬性,以設定其所建立的處理站,例如:AuthenticationScheme、HostNameComparisonMode 和 MaxBufferSize。
您也可以設定基底類別 TransportBindingElement 的屬性,例如:ManualAddressing、MaxReceivedMessageSize 和 MaxBufferPoolSize。 如需完整的屬性清單,請參閱 TransportBindingElement。
Http |
初始化 HttpTransportBindingElement 類別的新執行個體。 |
Http |
使用另一個繫結項目,初始化 HttpTransportBindingElement 類別的新執行個體。 |
Allow |
取得或設定值,這個值會指出用戶端是否接受 Cookie 並依未來要求傳播 Cookie。 |
Authentication |
取得或設定驗證配置,用於驗證由 HTTP 接聽程式處理的用戶端要求。 |
Bypass |
取得或設定值,指出是否忽略本機位址的 Proxy。 |
Decompression |
取得或設定是否已啟用傳回壓縮訊息資料至其原始大小與格式的程序。 |
Extended |
取得或設定值,這個值是伺服器用來驗證連入用戶端連線的延伸安全性原則。 |
Host |
取得或設定值,這個值會指出在比對 URI 時主機名稱是否會用來取用服務。 |
Keep |
取得或設定值,這個值表示是否要與服務端點建立持續連線。 |
Manual |
取得或設定值,這個值會指出是否需要訊息的手動定址。 (繼承來源 TransportBindingElement) |
Max |
取得或設定傳輸所使用之任何緩衝區集區的大小上限 (以位元組為單位)。 (繼承來源 TransportBindingElement) |
Max |
取得或設定要使用之緩衝區的大小上限。 對於經過緩衝處理的訊息,這個值與 MaxReceivedMessageSize 相同。 對於已進行資料流處理的訊息,這個值為 SOAP 標頭的最大大小 (必須在緩衝模式中讀取)。 |
Max |
取得或設定服務能夠同時接受的最大連線數。 |
Max |
取得或設定可接收之可允許的訊息大小上限 (以位元組為單位)。 (繼承來源 TransportBindingElement) |
Message |
取得或設定 Http 傳輸訊息處理常式 factory。 |
Proxy |
表示用來指定傳輸訊息之 HTTP 傳輸的繫結項目。 |
Proxy |
取得或設定 URI,包含用於 HTTP 要求的 Proxy 位址。 |
Proxy |
取得或設定驗證配置,用於驗證由 HTTP Proxy 處理的用戶端要求。 |
Realm |
取得或設定驗證領域。 |
Request |
取得或設定要求的初始設定逾時。 |
Scheme |
取得用於傳輸的 URI 配置。 |
Transfer |
取得或設定傳輸模式。 |
Unsafe |
取得或設定值,指出伺服器上是否啟用不安全的連線共用。 如果已啟用,NTLM 驗證會在各 TCP 連線上執行一次。 |
Use |
取得或設定值,指出是否使用全機器 Proxy 設定而非使用者特定設定。 |
Web |
取得或設定繫結項目的 Web 通訊端組態。 |
IPolicy |
匯出關於繫結的自訂原則判斷提示。 |
IWsdl |
將自訂的 Web 服務描述語言 (WSDL) 項目寫入為合約產生的 WSDL。 |
IWsdl |
將自訂的 Web 服務描述語言 (WSDL) 項目寫入為端點產生的 WSDL。 |
產品 | 版本 |
---|---|
.NET | Core 1.0, Core 1.1, 8 (package-provided), 9 (package-provided) |
.NET Framework | 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7 (package-provided), 4.7, 4.7.1 (package-provided), 4.7.1, 4.7.2 (package-provided), 4.7.2, 4.8 (package-provided), 4.8, 4.8.1 |
.NET Standard | 2.0 (package-provided) |
UWP | 10.0 |