WebClientProtocol 類別

定義

指定基底類別 (Base Class) 給所有使用 ASP.NET 來建立的 XML Web Service 用戶端 Proxy。

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

範例

下列範例是 ASP.NET Web Form,它會呼叫名為 的 Math XML Web 服務。 在 函 EnterBtn_Click 式中,Web Form 會在呼叫遠端 XML Web 服務方法之前,先在 Proxy 類別上設定 Proxy 資訊和用戶端認證。

重要

這個範例有一個可接受使用者輸入的文字方塊,這可能會造成安全性威脅。 根據預設,ASP.NET Web 網頁會驗證使用者輸入未包含指令碼或 HTML 項目。 如需詳細資訊,請參閱 Script Exploits Overview (指令碼攻擊概觀)。

<%@ 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();

             // Set the client-side credentials using the Credentials property.
             ICredentials credentials = new NetworkCredential("Joe","mydomain","password");
             math.Credentials = credentials;
             
             // Do not allow the server to redirect the request.
             math.AllowAutoRedirect = false;
             
             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()
            
            ' Set the client-side credentials using the Credentials property.
            Dim credentials As New NetworkCredential("Joe", "password", "mydomain")
            math.Credentials = credentials
            
            ' Do not allow the server to redirect the request.
            math.AllowAutoRedirect = False
            
            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>

備註

類別的屬性 WebClientProtocol 是用來控制傳輸 XML Web 服務要求和回應所使用的傳輸行為。 這個類別上的屬性會對應至 上 WebRequest 找到的屬性。 衍生自 WebRequest 的類別實例,例如 HttpWebRequest ,會作為使用 ASP.NET 所建立之 XML Web 服務的傳輸機制。

若要與 XML Web 服務通訊,您必須針對您想要呼叫的 XML Web 服務,間接或直接 WebClientProtocol 建立衍生的 Proxy 類別。 您可以使用Wsdl.exe工具來為指定的 XML Web 服務服務描述建立 Proxy 類別,而不是手動建立 Proxy 類別。 由於 WebClientProtocol 是用戶端 Proxy 的基類,因此您會在 Proxy 類別上找到其屬性。 這些屬性適用于控制基礎傳輸的要求行為。 例如,使用 Credentials 屬性來呼叫已驗證的 XML Web 服務。 WebClientProtocol許多屬性都用來初始化 WebRequest 用來提出 Web 要求的物件。

建構函式

WebClientProtocol()

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

屬性

CanRaiseEvents

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

(繼承來源 Component)
ConnectionGroupName

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

Container

取得包含 IContainerComponent

(繼承來源 Component)
Credentials

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

DesignMode

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

(繼承來源 Component)
Events

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

(繼承來源 Component)
PreAuthenticate

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

RequestEncoding

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

Site

取得或設定 ComponentISite

(繼承來源 Component)
Timeout

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

Url

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

UseDefaultCredentials

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

方法

Abort()

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

AddToCache(Type, Object)

將用戶端通訊協定處理常式的執行個體加入快取中。

CreateObjRef(Type)

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

(繼承來源 MarshalByRefObject)
Dispose()

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

(繼承來源 Component)
Dispose(Boolean)

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

(繼承來源 Component)
Equals(Object)

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

(繼承來源 Object)
GetFromCache(Type)

取得快取中用戶端通訊協定處理常式的執行個體。

GetHashCode()

做為預設雜湊函式。

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

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

(繼承來源 MarshalByRefObject)
GetService(Type)

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

(繼承來源 Component)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
GetWebRequest(Uri)

為指定的 uri 建立 WebRequest 執行個體。 這個保護的 (Protected) 方法由 XML Web Service 用戶端基礎結構所呼叫,以便取得新的 WebRequest 傳輸物件來傳輸 XML Web Service 要求。

GetWebResponse(WebRequest)

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

GetWebResponse(WebRequest, IAsyncResult)

從對 XML Web Service 方法的非同步要求傳回回應。 這個保護的方法由 XML Web Service 用戶端基礎結構所呼叫,以便從非同步 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 實例,或提供您自己的同步處理。

另請參閱