HttpGetClientProtocol 類別

定義

這是使用 HTTP-GET 協定的 XML Web 服務用戶端代理的基底類別。

public ref class HttpGetClientProtocol : System::Web::Services::Protocols::HttpSimpleClientProtocol
public class HttpGetClientProtocol : System.Web.Services.Protocols.HttpSimpleClientProtocol
type HttpGetClientProtocol = class
    inherit HttpSimpleClientProtocol
Public Class HttpGetClientProtocol
Inherits HttpSimpleClientProtocol
繼承

範例

以下範例是由 Wsdl.exe Math 為下列 XML Web 服務產生的代理類別。 代理類由 HttpGetClientProtocol衍生而來,而 又由抽象 HttpSimpleClientProtocol 類衍生而來。

#using <System.Web.Services.dll>
#using <System.Xml.dll>
#using <System.dll>

using namespace System::Diagnostics;
using namespace System::Xml::Serialization;
using namespace System;
using namespace System::Web::Services::Protocols;
using namespace System::Web::Services;

public ref class MyMath: public System::Web::Services::Protocols::HttpGetClientProtocol
{
public:

   [System::Diagnostics::DebuggerStepThroughAttribute]
   MyMath()
   {
      this->Url = "http://www.contoso.com/math.asmx";
   }

   [System::Diagnostics::DebuggerStepThroughAttribute]
   [System::Web::Services::Protocols::HttpMethodAttribute(System::Web::Services::Protocols::XmlReturnReader::typeid,
   System::Web::Services::Protocols::UrlParameterWriter::typeid)]
   [returnvalue:System::Xml::Serialization::XmlRootAttribute("snippet1>",Namespace="http://www.contoso.com/",IsNullable=false)]
   int Add( String^ num1, String^ num2 )
   {
      array<Object^>^temp0 = {num1,num2};
      return  *dynamic_cast<int^>(this->Invoke( "Add", (String::Concat( this->Url, "/Add" )), temp0 ));
   }

   [System::Diagnostics::DebuggerStepThroughAttribute]
   System::IAsyncResult^ BeginAdd( String^ num1, String^ num2, System::AsyncCallback^ callback, Object^ asyncState )
   {
      array<Object^>^temp1 = {num1,num2};
      return this->BeginInvoke( "Add", (String::Concat( this->Url, "/Add" )), temp1, callback, asyncState );
   }

   [System::Diagnostics::DebuggerStepThroughAttribute]
   int EndAdd( System::IAsyncResult^ asyncResult )
   {
      return  *dynamic_cast<int^>(this->EndInvoke( asyncResult ));
   }
};
using System.Diagnostics;
using System.Xml.Serialization;
using System;
using System.Web.Services.Protocols;
using System.Web.Services;

public class MyMath : System.Web.Services.Protocols.HttpGetClientProtocol {

    [System.Diagnostics.DebuggerStepThroughAttribute()]
    public MyMath()
    {
        this.Url = "http://www.contoso.com/math.asmx";
    }

    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.Web.Services.Protocols.HttpMethodAttribute(typeof(System.Web.Services.Protocols.XmlReturnReader), typeof(System.Web.Services.Protocols.UrlParameterWriter))]
    [return: System.Xml.Serialization.XmlRootAttribute("int", Namespace = "http://www.contoso.com/", IsNullable = false)]
    public int Add(string num1, string num2)
    {
        return ((int)(this.Invoke("Add", (this.Url + "/Add"),
            new object[] { num1, num2 })));
    }

    [System.Diagnostics.DebuggerStepThroughAttribute()]
    public System.IAsyncResult BeginAdd(string num1, string num2, System.AsyncCallback callback, object asyncState)
    {
        return this.BeginInvoke("Add", (this.Url + "/Add"),
            new object[] { num1, num2 }, callback, asyncState);
    }

    [System.Diagnostics.DebuggerStepThroughAttribute()]
    public int EndAdd(System.IAsyncResult asyncResult)
    {
        return ((int)(this.EndInvoke(asyncResult)));
    }
}
Option Strict On
Option Explicit On

Imports System.Diagnostics
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Xml.Serialization


Public Class MyMath
    Inherits System.Web.Services.Protocols.HttpGetClientProtocol
    
    <System.Diagnostics.DebuggerStepThroughAttribute()>  _
    Public Sub New()
        MyBase.New
        Me.Url = "http://www.contoso.com/math.asmx"
    End Sub
    
    <System.Diagnostics.DebuggerStepThroughAttribute(),  _
     System.Web.Services.Protocols.HttpMethodAttribute(GetType(System.Web.Services.Protocols.XmlReturnReader), GetType(System.Web.Services.Protocols.UrlParameterWriter))>  _
    Public Function Add(ByVal num1 As String, ByVal num2 As String) As <System.Xml.Serialization.XmlRootAttribute("int", [Namespace]:="http://www.contoso.com/", IsNullable:=false)> Integer
        Return CType(Me.Invoke("Add", (Me.Url + "/Add"), New Object() {num1, num2}),Integer)
    End Function
    
    <System.Diagnostics.DebuggerStepThroughAttribute()>  _
    Public Function BeginAdd(ByVal num1 As String, ByVal num2 As String, ByVal callback As System.AsyncCallback, ByVal asyncState As Object) As System.IAsyncResult
        Return Me.BeginInvoke("Add", (Me.Url + "/Add"), New Object() {num1, num2}, callback, asyncState)
    End Function
    
    <System.Diagnostics.DebuggerStepThroughAttribute()>  _
    Public Function EndAdd(ByVal asyncResult As System.IAsyncResult) As Integer
        Return CType(Me.EndInvoke(asyncResult),Integer)
    End Function
End Class

以下範例是 Math XML Web 服務,上述代理類別即由此產生。

<%@ WebService Language="C#" Class="Math"%>
 using System.Web.Services;
 using System;
 
 public class Math {
      [ WebMethod ]
      public int Add(int num1, int num2) {
          return num1+num2;
          }
 }
<%@ WebService Language="VB" Class="Math"%>
Imports System.Web.Services
Imports System

Public Class Math
    <WebMethod()> _
    Public Function Add(num1 As Integer, num2 As Integer) As Integer
        Return num1 + num2
    End Function 'Add
End Class 'Math

備註

當 XML Web 服務客戶端使用 HTTP-GET 協定時,參數會編碼在 URL 中,回應則以純 XML 格式回傳。

如果你正在使用 ASP.NET 建置 XML Web 服務客戶端,那麼你需要為你想呼叫的 XML Web 服務建立一個間接或直接從 WebClientProtocol 衍生的代理類別。 當 XML Web 服務用戶端使用 HTTP 呼叫 XML Web 服務時,從 推導代理類別,而代理類別 HttpSimpleClientProtocol又從 衍生出 WebClientProtocol

HttpGetClientProtocol 以及 HttpPostClientProtocol 源自 HttpSimpleClientProtocol,分別支援使用 HTTP-GET 和 HTTP-POST 協定呼叫 XML Web 服務方法。 使用 SOAP 呼叫 XML 網路服務的用戶端應由 衍生出 SoapHttpClientProtocol

關於建立代理類別的詳細資訊,請參見 建立 XML Web Service 代理

建構函式

名稱 Description
HttpGetClientProtocol()

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

屬性

名稱 Description
AllowAutoRedirect

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

(繼承來源 HttpWebClientProtocol)
CanRaiseEvents

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

(繼承來源 Component)
ClientCertificates

取得客戶憑證的收集。

(繼承來源 HttpWebClientProtocol)
ConnectionGroupName

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

(繼承來源 WebClientProtocol)
Container

得到 IContainer 包含 Component的 。

(繼承來源 Component)
CookieContainer

收集或設定餅乾的集合。

(繼承來源 HttpWebClientProtocol)
Credentials

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

(繼承來源 WebClientProtocol)
DesignMode

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

(繼承來源 Component)
EnableDecompression

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

(繼承來源 HttpWebClientProtocol)
Events

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

(繼承來源 Component)
PreAuthenticate

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

(繼承來源 WebClientProtocol)
Proxy

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

(繼承來源 HttpWebClientProtocol)
RequestEncoding

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

(繼承來源 WebClientProtocol)
Site

取得或設定 ISiteComponent

(繼承來源 Component)
Timeout

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

(繼承來源 WebClientProtocol)
UnsafeAuthenticatedConnectionSharing

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

(繼承來源 HttpWebClientProtocol)
Url

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

(繼承來源 WebClientProtocol)
UseDefaultCredentials

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

(繼承來源 WebClientProtocol)
UserAgent

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

(繼承來源 HttpWebClientProtocol)

方法

名稱 Description
Abort()

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

(繼承來源 WebClientProtocol)
BeginInvoke(String, String, Object[], AsyncCallback, Object)

啟動非同步呼叫 XML Web 服務的方法。

(繼承來源 HttpSimpleClientProtocol)
CancelAsync(Object)

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

(繼承來源 HttpWebClientProtocol)
CreateObjRef(Type)

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

(繼承來源 MarshalByRefObject)
Dispose()

釋放所有由 Component.

(繼承來源 Component)
Dispose(Boolean)

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

(繼承來源 Component)
EndInvoke(IAsyncResult)

完成使用 HTTP 的非同步呼叫 XML Web 服務方法。

(繼承來源 HttpSimpleClientProtocol)
Equals(Object)

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

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetLifetimeService()

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

(繼承來源 MarshalByRefObject)
GetService(Type)

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

(繼承來源 Component)
GetType()

取得目前實例的 Type

(繼承來源 Object)
GetWebRequest(Uri)

為指定的 URI 建立一個 WebRequest 實例。

GetWebResponse(WebRequest, IAsyncResult)

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

(繼承來源 HttpWebClientProtocol)
GetWebResponse(WebRequest)

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

(繼承來源 HttpWebClientProtocol)
InitializeLifetimeService()

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

(繼承來源 MarshalByRefObject)
Invoke(String, String, Object[])

呼叫使用 HTTP 的 XML Web 服務方法。

(繼承來源 HttpSimpleClientProtocol)
InvokeAsync(String, String, Object[], SendOrPostCallback, Object)

非同步呼叫指定方法,同時維持相關狀態。

(繼承來源 HttpSimpleClientProtocol)
InvokeAsync(String, String, Object[], SendOrPostCallback)

非同步呼叫指定方法。

(繼承來源 HttpSimpleClientProtocol)
MemberwiseClone()

建立目前 Object的淺層複本。

(繼承來源 Object)
MemberwiseClone(Boolean)

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

(繼承來源 MarshalByRefObject)
ToString()

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

(繼承來源 Component)

事件

名稱 Description
Disposed

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

(繼承來源 Component)

適用於

另請參閱