HttpWebClientProtocol 類別

定義

表示所有使用 HTTP 傳輸通訊協定之 XML Web Service 用戶端 Proxy 的基底類別。

public ref class HttpWebClientProtocol abstract : System::Web::Services::Protocols::WebClientProtocol
public abstract class HttpWebClientProtocol : System.Web.Services.Protocols.WebClientProtocol
[System.Runtime.InteropServices.ComVisible(true)]
public abstract class HttpWebClientProtocol : System.Web.Services.Protocols.WebClientProtocol
type HttpWebClientProtocol = class
    inherit WebClientProtocol
[<System.Runtime.InteropServices.ComVisible(true)>]
type HttpWebClientProtocol = class
    inherit WebClientProtocol
Public MustInherit Class HttpWebClientProtocol
Inherits WebClientProtocol
繼承
衍生
屬性

範例

下列範例是 ASP.NET Web Form,它會呼叫名為 的 Math XML Web 服務。 在 函 EnterBtn_Click 式中,Web Form 可讓伺服器自動將用戶端重新導向至其他網站。 它也會設定用戶端驗證認證、Proxy 設定、要求編碼和要求逾時,再呼叫 XML Web 服務方法。

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Net" %>

<html>
    <script language="C#" runat="server">
       void EnterBtn_Click(Object Src, EventArgs E) 
          {
             MyMath.Math math = new MyMath.Math();

             // Allow the server to redirect the request.
             math.AllowAutoRedirect = true;

             // Set the client-side credentials using the Credentials property.
             ICredentials credentials =
                new NetworkCredential("Joe","password","mydomain");
             math.Credentials = credentials;

             // Set the proxy server to proxyserver, set the port to 80, and specify to bypass
             // the proxy server for local addresses.
             IWebProxy proxyObject = new WebProxy("http://proxyserver:80",true);
             math.Proxy = proxyObject;

             // Set the encoding to utf-8.
             math.RequestEncoding = System.Text.Encoding.UTF8;

             // Set the time out to 15 seconds
             math.Timeout = 15000;

             int total = math.Add(Convert.ToInt32(Num1.Text),
                Convert.ToInt32(Num2.Text));
             Total.Text = "Total: " + total.ToString();
         }
 
    </script>
 
    <body>
       <form action="MathClient.aspx" runat=server>
           
          Enter the two numbers you want to add and then press the Total button.
          <p>
          Number 1: <asp:textbox id="Num1" runat=server/>  +
          Number 2: <asp:textbox id="Num2" runat=server/> =
          <asp:button text="Total" Onclick="EnterBtn_Click" runat=server/>
          <p>
          <asp:label id="Total"  runat=server/>
          
       </form>
    </body>
 </html>
   
<%@ Page Language="VB" %>
<%@ Import Namespace="System.Net" %>

<html>
    <script language="VB" runat="server">

    Sub EnterBtn_Click(Src As Object, E As EventArgs)
        Dim math As New MyMath.Math()
        
        ' Allow the server to redirect the request.
        math.AllowAutoRedirect = True
        
        ' Set the client-side credentials using the Credentials property.
        Dim credentials = New NetworkCredential("Joe", "password", "mydomain")
        math.Credentials = credentials
        
        ' Set the proxy server to proxyserver, set the port to 80 and specify to bypass
        ' the proxy server for local addresses.
        Dim proxyObject = New WebProxy("http://proxyserver:80", True)
        math.Proxy = proxyObject
        
        ' Set the encoding to utf-8.
        math.RequestEncoding = System.Text.Encoding.UTF8
        
        ' Set the time out to 15 seconds.
        math.Timeout = 15000
        
        Dim iTotal As Integer = math.Add(Convert.ToInt32(Num1.Text), _
           Convert.ToInt32(Num2.Text))
        Total.Text = "Total: " & iTotal.ToString()
    End Sub
 
    </script>
 
    <body>
       <form action="MathClient.aspx" runat=server>
           
          Enter the two numbers you want to add and then press the Total button.
          <p>
          Number 1: <asp:textbox id="Num1" runat=server/>  +
          Number 2: <asp:textbox id="Num2" runat=server/> =
          <asp:button text="Total" Onclick="EnterBtn_Click" runat=server/>
          <p>
          <asp:label id="Total"  runat=server/>
          
       </form>
    </body>
 </html>
   

備註

這個類別上的屬性是用來控制 HTTP 要求物件的行為,這些物件是用來傳輸 XML Web 服務要求和回應。 屬性會對應至 上 HttpWebRequest 找到的屬性。

若要使用 HTTP 與 XML Web 服務通訊,您必須為 XML Web 服務建立衍生或直接衍生的 HttpWebClientProtocol Proxy 類別。 您可以使用 Wsdl.exe 工具來為指定的 XML Web 服務服務描述建立 Proxy 類別,而不是手動建立 Proxy 類別。

由於 HttpWebClientProtocol 是所有 Proxy 類別的基類,因此其屬性會位於您的 Proxy 類別上。 這些屬性適用于控制基礎傳輸的要求行為。 例如,使用 Proxy 屬性透過防火牆呼叫 XML Web 服務。 其中許多屬性是用來初始化 HttpWebRequest 發出 Web 要求的 。

SoapHttpClientProtocolHttpGetClientProtocolHttpPostClientProtocol 直接或間接衍生自 HttpWebClientProtocol ,分別提供 SOAP、HTTP-GET 和 HTTP-POST 的支援。

建構函式

HttpWebClientProtocol()

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

屬性

AllowAutoRedirect

取得或設定用戶端是否自動遵循伺服器重新導向。

CanRaiseEvents

取得值,指出元件是否能引發事件。

(繼承來源 Component)
ClientCertificates

取得用戶端憑證的集合。

ConnectionGroupName

取得或設定要求的連線群組名稱。

(繼承來源 WebClientProtocol)
Container

取得包含 IContainerComponent

(繼承來源 Component)
CookieContainer

取得或設定 Cookie 的集合。

Credentials

取得或設定 XML Web Service 用戶端驗證 (Authentication) 的安全認證。

(繼承來源 WebClientProtocol)
DesignMode

取得值,指出 Component 目前是否處於設計模式。

(繼承來源 Component)
EnableDecompression

取得或設定值,指出是否已啟用這個 HttpWebClientProtocol 的解壓縮。

Events

取得附加在這個 Component 上的事件處理常式清單。

(繼承來源 Component)
PreAuthenticate

取得或設定是否已啟用預先驗證。

(繼承來源 WebClientProtocol)
Proxy

取得或設定 Proxy 資訊,以製作穿越防火牆的 XML Web Service 要求。

RequestEncoding

Encoding,用來建立對 XML Web Service 的用戶端要求。

(繼承來源 WebClientProtocol)
Site

取得或設定 ComponentISite

(繼承來源 Component)
Timeout

表示 XML Web Service 用戶端等待同步 XML Web Service 要求的回覆到達的時間 (單位為毫秒)。

(繼承來源 WebClientProtocol)
UnsafeAuthenticatedConnectionSharing

取得或設定值,指出是否在用戶端使用 NTLM 驗證連接到裝載 XML Web Service 的 Web 伺服器時啟用連線共用。

Url

取得或設定用戶端正在要求之 XML Web Service 的基礎 URL。

(繼承來源 WebClientProtocol)
UseDefaultCredentials

取得或設定值,指出是否將 Credentials 屬性設為 DefaultCredentials 屬性的值。

(繼承來源 WebClientProtocol)
UserAgent

針對隨著每個要求所傳送的使用者代理標頭,取得或設定值。

方法

Abort()

取消對 XML Web Service 方法的要求。

(繼承來源 WebClientProtocol)
CancelAsync(Object)

取消對 XML Web Service 方法的非同步呼叫,除非呼叫已完成。

CreateObjRef(Type)

建立包含所有相關資訊的物件,這些資訊是產生用來與遠端物件通訊的所需 Proxy。

(繼承來源 MarshalByRefObject)
Dispose()

釋放 Component 所使用的所有資源。

(繼承來源 Component)
Dispose(Boolean)

釋放 Component 所使用的 Unmanaged 資源,並選擇性地釋放 Managed 資源。

(繼承來源 Component)
Equals(Object)

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

(繼承來源 Object)
GenerateXmlMappings(Type, ArrayList)

取得指定型別所公開之每個 XML Web Service 方法的 XmlMembersMapping,並將對應儲存在指定的 ArrayList 中。

GenerateXmlMappings(Type[], ArrayList)

取得指定型別所公開之每一個 XML Web Service 方法的 XmlMembersMapping,並將對應儲存在指定的 ArrayList 中,以及儲存在這個方法傳回的 Hashtable 中。

GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetLifetimeService()
已過時。

擷取控制這個執行個體存留期 (Lifetime) 原則的目前存留期服務物件。

(繼承來源 MarshalByRefObject)
GetService(Type)

傳回表示 Component 或其 Container 所提供之服務的物件。

(繼承來源 Component)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
GetWebRequest(Uri)

建立指定 URL 的 WebRequest

GetWebResponse(WebRequest)

從對 XML Web Service 方法的同步要求傳回回應。

GetWebResponse(WebRequest, IAsyncResult)

從對 XML Web Service 方法的非同步要求傳回回應。

InitializeLifetimeService()
已過時。

取得存留期服務物件,以控制這個執行個體的存留期原則。

(繼承來源 MarshalByRefObject)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
MemberwiseClone(Boolean)

建立目前 MarshalByRefObject 物件的淺層複本。

(繼承來源 MarshalByRefObject)
ToString()

傳回任何包含 Component 名稱的 String。 不應覆寫此方法。

(繼承來源 Component)

事件

Disposed

Dispose() 方法的呼叫處置元件時,就會發生。

(繼承來源 Component)

適用於

執行緒安全性

這個類別上的屬性會針對每個 XML Web 服務方法呼叫,複製到 物件的新實例 WebRequest 中。 雖然您可以在相同 WebClientProtocol 實例上同時從不同的執行緒呼叫 XML Web 服務方法,但不會進行同步處理,以確保屬性的一致快照集會傳送至 WebRequest 物件。 因此,如果您需要修改屬性,並從不同的執行緒進行並行方法呼叫,您應該使用不同的 XML Web 服務 Proxy 實例,或提供您自己的同步處理。

另請參閱