WebClientProtocol 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
規定所有使用 ASP.NET 建立的 XML Web 服務用戶端代理的基底類別。
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
- 繼承
- 衍生
- 屬性
範例
下列範例是 ASP.NET Web Form,它會呼叫名為 Math的 XML Web 服務。 在 EnterBtn_Click 函式中,Web Form 會在呼叫遠端 XML Web 服務方法之前,先在 Proxy 類別上設定 Proxy 資訊和客戶端認證。
Important
此範例中有一個文字框可接受使用者輸入,這可能構成安全威脅。 預設情況下,ASP.NET 網頁會驗證使用者輸入中不包含腳本或 HTML 元素。 欲了解更多資訊,請參閱 腳本漏洞概述。
<%@ 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 屬性都用來初始化用來提出 Web 要求的 WebRequest 物件。
建構函式
| 名稱 | Description |
|---|---|
| WebClientProtocol() |
初始化 WebClientProtocol 類別的新執行個體。 |
屬性
| 名稱 | Description |
|---|---|
| CanRaiseEvents |
會得到一個值,表示該元件是否能引發事件。 (繼承來源 Component) |
| ConnectionGroupName |
取得或設定請求的連線群組名稱。 |
| Container |
得到 IContainer 包含 Component的 。 (繼承來源 Component) |
| Credentials |
取得或設定 XML Web 服務客戶端驗證的安全性認證。 |
| DesignMode |
會得到一個值,表示目前 Component 是否處於設計模式。 (繼承來源 Component) |
| Events |
會取得與此 Component連結的事件處理程序清單。 (繼承來源 Component) |
| PreAuthenticate |
取得或設定是否啟用預先驗證。 |
| RequestEncoding |
用來向 XML Web 服務提出用戶端要求 Encoding。 |
| Site | (繼承來源 Component) |
| Timeout |
表示 XML Web 服務用戶端等候回復至同步 XML Web 服務要求的時間(以毫秒為單位)。 |
| Url |
取得或設定用戶端要求之 XML Web 服務的基底 URL。 |
| UseDefaultCredentials |
取得或設定值,這個值表示是否要將 Credentials 屬性設定為 DefaultCredentials 屬性的值。 |
方法
| 名稱 | Description |
|---|---|
| Abort() |
取消對 XML Web 服務方法的要求。 |
| AddToCache(Type, Object) |
將用戶端通訊協議處理程序的實例新增至快取。 |
| CreateObjRef(Type) |
建立一個物件,包含產生代理伺服器所需的所有相關資訊,用於與遠端物件通訊。 (繼承來源 MarshalByRefObject) |
| Dispose() |
釋放所有由 Component. (繼承來源 Component) |
| Dispose(Boolean) |
釋放 未管理的資源, Component 並可選擇性地釋放受管理資源。 (繼承來源 Component) |
| Equals(Object) |
判斷指定的 物件是否等於目前的物件。 (繼承來源 Object) |
| GetFromCache(Type) |
從快取取得用戶端通訊協議處理程序的實例。 |
| GetHashCode() |
做為預設雜湊函式。 (繼承來源 Object) |
| GetLifetimeService() |
取得目前控制此實例生命週期政策的終身服務物件。 (繼承來源 MarshalByRefObject) |
| GetService(Type) |
回傳一個由 或Component其 所提供的Container服務的物件。 (繼承來源 Component) |
| GetType() |
取得目前實例的 Type。 (繼承來源 Object) |
| GetWebRequest(Uri) |
為指定的 WebRequest建立 |
| GetWebResponse(WebRequest, IAsyncResult) |
從異步要求傳回 XML Web 服務方法的回應。 XML Web 服務用戶端基礎結構會呼叫這個受保護的方法,以從異步 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 服務 Proxy 實例,或提供您自己的同步處理。