HttpWebClientProtocol 類別

定義

表示所有使用 HTTP 傳輸通訊協定之 XML Web 服務用戶端 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 式中,網頁表單允許伺服器自動將用戶端導向至其他網站。 它同時設定用戶端認證憑證、代理設定、請求編碼及請求逾時,然後再呼叫 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>
   

備註

此類別的屬性用來控制用於傳輸 XML Web 服務請求與回應的 HTTP 請求物件的行為。 這些屬性映射到 在 HttpWebRequest上的屬性。

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

由於 HttpWebClientProtocol 是所有代理類別的基底類別,它的屬性都存在於你的代理類別上。 這些屬性適用於控制基礎傳輸的要求行為。 例如,使用透過 Proxy 防火牆呼叫 XML Web 服務的特性。 許多這些屬性用來初始化發出網路請求的物件 HttpWebRequest

SoapHttpClientProtocol HttpGetClientProtocol HttpPostClientProtocol、分別直接或間接地從 衍生,HttpWebClientProtocol以支援 SOAP、HTTP-GET 和 HTTP-POST。

建構函式

名稱 Description
HttpWebClientProtocol()

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

屬性

名稱 Description
AllowAutoRedirect

是自動執行伺服器重定向,還是設定。

CanRaiseEvents

會得到一個值,表示該元件是否能引發事件。

(繼承來源 Component)
ClientCertificates

取得客戶憑證的收集。

ConnectionGroupName

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

(繼承來源 WebClientProtocol)
Container

得到 IContainer 包含 Component的 。

(繼承來源 Component)
CookieContainer

收集或設定餅乾的集合。

Credentials

取得或設定 XML Web 服務客戶端驗證的安全性認證。

(繼承來源 WebClientProtocol)
DesignMode

會得到一個值,表示目前 Component 是否處於設計模式。

(繼承來源 Component)
EnableDecompression

取得或設定一個值,指示是否啟用 HttpWebClientProtocol解壓。

Events

會取得與此 Component連結的事件處理程序清單。

(繼承來源 Component)
PreAuthenticate

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

(繼承來源 WebClientProtocol)
Proxy

透過防火牆取得或設定代理資訊,以發送 XML 網路服務請求。

RequestEncoding

用來向 XML Web 服務提出用戶端要求 Encoding

(繼承來源 WebClientProtocol)
Site

取得或設定 ISiteComponent

(繼承來源 Component)
Timeout

表示 XML Web 服務用戶端等候回復至同步 XML Web 服務要求的時間(以毫秒為單位)。

(繼承來源 WebClientProtocol)
UnsafeAuthenticatedConnectionSharing

當用戶端使用 NTLM 認證連接承載 XML 網路服務的 Web 伺服器時,會取得或設定一個值,指示是否啟用連線共享。

Url

取得或設定用戶端要求之 XML Web 服務的基底 URL。

(繼承來源 WebClientProtocol)
UseDefaultCredentials

取得或設定值,這個值表示是否要將 Credentials 屬性設定為 DefaultCredentials 屬性的值。

(繼承來源 WebClientProtocol)
UserAgent

取得或設定每次請求中傳送的使用者代理標頭值。

方法

名稱 Description
Abort()

取消對 XML Web 服務方法的要求。

(繼承來源 WebClientProtocol)
CancelAsync(Object)

取消對 XML Web 服務方法的非同步呼叫,除非該呼叫已經完成。

CreateObjRef(Type)

建立一個物件,包含產生代理伺服器所需的所有相關資訊,用於與遠端物件通訊。

(繼承來源 MarshalByRefObject)
Dispose()

釋放所有由 Component.

(繼承來源 Component)
Dispose(Boolean)

釋放 未管理的資源, Component 並可選擇性地釋放受管理資源。

(繼承來源 Component)
Equals(Object)

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

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

取得 XmlMembersMapping 每個 XML Web 服務方法的指定型別所暴露的 ,並將映射儲存在指定的 ArrayList

GenerateXmlMappings(Type[], ArrayList)

取得每個 XML Web 服務方法的 , XmlMembersMapping 這些 由指定類型暴露,並將映射儲存在指定的 ArrayList中,同時也儲存在該方法回傳的 中 Hashtable

GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetLifetimeService()

取得目前控制此實例生命週期政策的終身服務物件。

(繼承來源 MarshalByRefObject)
GetService(Type)

回傳一個由 或Component其 所提供的Container服務的物件。

(繼承來源 Component)
GetType()

取得目前實例的 Type

(繼承來源 Object)
GetWebRequest(Uri)

為指定的 URI 建立 a WebRequest

GetWebResponse(WebRequest, IAsyncResult)

從異步要求傳回 XML Web 服務方法的回應。

GetWebResponse(WebRequest)

從同步要求傳回 XML Web 服務方法的回應。

InitializeLifetimeService()

取得一個終身服務物件以控制此實例的終身政策。

(繼承來源 MarshalByRefObject)
MemberwiseClone()

建立目前 Object的淺層複本。

(繼承來源 Object)
MemberwiseClone(Boolean)

建立一個 MarshalByRefObject 目前物件的淺層複製品。

(繼承來源 MarshalByRefObject)
ToString()

回傳 String 包含 的名稱 Component(若有的話)。 此方法不應被覆蓋。

(繼承來源 Component)

事件

名稱 Description
Disposed

當元件被呼叫方法 Dispose() 時會發生。

(繼承來源 Component)

適用於

執行緒安全性

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

另請參閱