SoapHttpClientProtocol 類別

定義

指定使用 SOAP 時做為衍生 Proxy 來源的類別用戶端。

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

範例

下列程式碼範例是 XML Web 服務Wsdl.exe Math 所產生的 Proxy 類別。 Proxy 類別衍生自 SoapHttpClientProtocol ,其衍生自抽象 WebClientProtocol 類。

#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;

namespace MyMath
{

   [System::Web::Services::WebServiceBindingAttribute(Name="MyMathSoap",Namespace="http://www.contoso.com/")]
   public ref class MyMath: public System::Web::Services::Protocols::SoapHttpClientProtocol
   {
   public:

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


      [System::Diagnostics::DebuggerStepThroughAttribute]
      [System::Web::Services::Protocols::SoapDocumentMethodAttribute("http://www.contoso.com/Add",
      RequestNamespace="http://www.contoso.com/",ResponseNamespace="http://www.contoso.com/",
      Use=System::Web::Services::Description::SoapBindingUse::Literal,
      ParameterStyle=System::Web::Services::Protocols::SoapParameterStyle::Wrapped)]
      int Add( int num1, int num2 )
      {
         array<Object^>^temp0 = {num1,num2};
         array<Object^>^results = this->Invoke( "Add", temp0 );
         return  *dynamic_cast<int^>(results[ 0 ]);
      }


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


      [System::Diagnostics::DebuggerStepThroughAttribute]
      int EndAdd( System::IAsyncResult^ asyncResult )
      {
         array<Object^>^results = this->EndInvoke( asyncResult );
         return  *dynamic_cast<int^>(results[ 0 ]);
      }

   };

}


namespace MyMath {
    using System.Diagnostics;
    using System.Xml.Serialization;
    using System;
    using System.Web.Services.Protocols;
    using System.Web.Services;

    [System.Web.Services.WebServiceBindingAttribute(Name="MyMathSoap", Namespace="http://www.contoso.com/")]
    public class MyMath : System.Web.Services.Protocols.SoapHttpClientProtocol {

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

        [System.Diagnostics.DebuggerStepThroughAttribute()]
        [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://www.contoso.com/Add", RequestNamespace="http://www.contoso.com/", ResponseNamespace="http://www.contoso.com/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
        public int Add(int num1, int num2) {
            object[] results = this.Invoke("Add", new object[] {num1,
                        num2});
            return ((int)(results[0]));
        }

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

        [System.Diagnostics.DebuggerStepThroughAttribute()]
        public int EndAdd(System.IAsyncResult asyncResult) {
            object[] results = this.EndInvoke(asyncResult);
            return ((int)(results[0]));
        }
    }
}

Option Strict On
Option Explicit On

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

Namespace MyMath
    
    <System.Web.Services.WebServiceBindingAttribute(Name:="MyMathSoap", [Namespace]:="http://www.contoso.com/")>  _
    Public Class MyMath
        Inherits System.Web.Services.Protocols.SoapHttpClientProtocol
        
        <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.SoapDocumentMethodAttribute("http://www.contoso.com/Add", RequestNamespace:="http://www.contoso.com/", ResponseNamespace:="http://www.contoso.com/", Use:=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle:=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)>  _
        Public Function Add(ByVal num1 As Integer, ByVal num2 As Integer) As Integer
            Dim results() As Object = Me.Invoke("Add", New Object() {num1, num2})
            Return CType(results(0),Integer)
        End Function
        
        <System.Diagnostics.DebuggerStepThroughAttribute()>  _
        Public Function BeginAdd(ByVal num1 As Integer, ByVal num2 As Integer, ByVal callback As System.AsyncCallback, ByVal asyncState As Object) As System.IAsyncResult
            Return Me.BeginInvoke("Add", New Object() {num1, num2}, callback, asyncState)
        End Function
        
        <System.Diagnostics.DebuggerStepThroughAttribute()>  _
        Public Function EndAdd(ByVal asyncResult As System.IAsyncResult) As Integer
            Dim results() As Object = Me.EndInvoke(asyncResult)
            Return CType(results(0),Integer)
        End Function
    End Class
End Namespace

下列程式碼範例是 Math XML Web 服務,從中產生上述 Proxy 類別。

重要

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

<%@ WebService Language="C#" Class="MyMath"%>
 using System.Web.Services;
 using System;
 
 [WebService(Namespace="http://www.contoso.com/")] 
 public class MyMath {
    
    [ WebMethod ]
    public int Add(int num1, int num2) {
        return num1+num2;
    }
 }
<%@ WebService Language="VB" Class="MyMath"%>
Imports System.Web.Services
Imports System

<WebService(Namespace:="http://www.contoso.com/")> _
Public Class MyMath
    <WebMethod()> _
    Public Function Add(num1 As Integer, num2 As Integer) As Integer
        Return num1 + num2
    End Function 'Add
End Class 'Math

備註

如果您要建置 XML Web 服務用戶端,則必須為 XML Web 服務建立間接或直接衍生自 WebClientProtocol 的 Proxy 類別。 當 XML Web 服務用戶端使用 SOAP 呼叫時,Proxy 類別必須衍生自 SoapHttpClientProtocol ,其衍生自 HttpWebClientProtocolHttpWebClientProtocol接著,衍生自 WebClientProtocol

若要與 XML Web 服務通訊,請針對您想要呼叫的 XML Web 服務,建立間接衍生或直接衍生的 WebClientProtocol Proxy 類別。 不使用手動建立 Proxy 類別,請使用 Web 服務描述語言工具 (Wsdl.exe) ,為指定的 XML Web 服務服務描述建立 Proxy 類別。 產生 SOAP 通訊協定的 Proxy 類別時,會透過 Invoke 方法對 XML Web 服務方法進行同步呼叫,而非同步呼叫則是使用 BeginInvoke 方法和 EndInvoke 方法進行。

給繼承者的注意事項

當您覆寫此類別時,可以在衍生類別中導入特定類型 XML Web 服務特有的方法。 方法會擷取參數並呼叫基類,以執行與 XML Web 服務通訊的工作。 如果引進的方法是非同步,請呼叫 BeginInvoke(String, Object[], AsyncCallback, Object) 方法和 EndInvoke(IAsyncResult) 方法。 如果引進的方法是同步的,請呼叫 Invoke(String, Object[]) 方法。 覆寫的建構函式通常會將 Url 屬性設定為 XML Web 服務方法的 URL。

建構函式

SoapHttpClientProtocol()

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

屬性

AllowAutoRedirect

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

(繼承來源 HttpWebClientProtocol)
CanRaiseEvents

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

(繼承來源 Component)
ClientCertificates

取得用戶端憑證的集合。

(繼承來源 HttpWebClientProtocol)
ConnectionGroupName

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

(繼承來源 WebClientProtocol)
Container

取得包含 IContainerComponent

(繼承來源 Component)
CookieContainer

取得或設定 Cookie 的集合。

(繼承來源 HttpWebClientProtocol)
Credentials

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

(繼承來源 WebClientProtocol)
DesignMode

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

(繼承來源 Component)
EnableDecompression

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

(繼承來源 HttpWebClientProtocol)
Events

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

(繼承來源 Component)
PreAuthenticate

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

(繼承來源 WebClientProtocol)
Proxy

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

(繼承來源 HttpWebClientProtocol)
RequestEncoding

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

(繼承來源 WebClientProtocol)
Site

取得或設定 ComponentISite

(繼承來源 Component)
SoapVersion

取得或設定 SOAP 通訊協定的版本,用於對 XML Web Service 發出 SOAP 要求。

Timeout

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

(繼承來源 WebClientProtocol)
UnsafeAuthenticatedConnectionSharing

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

(繼承來源 HttpWebClientProtocol)
Url

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

(繼承來源 WebClientProtocol)
UseDefaultCredentials

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

(繼承來源 WebClientProtocol)
UserAgent

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

(繼承來源 HttpWebClientProtocol)

方法

Abort()

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

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

使用 SOAP 啟動 XML Web Service 方法的非同步引動過程。

CancelAsync(Object)

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

(繼承來源 HttpWebClientProtocol)
CreateObjRef(Type)

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

(繼承來源 MarshalByRefObject)
Discover()

動態繫結至 Url 的探索文件中所述的 XML Web Service。

Dispose()

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

(繼承來源 Component)
Dispose(Boolean)

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

(繼承來源 Component)
EndInvoke(IAsyncResult)

使用 SOAP 結束 XML Web Service 方法的非同步引動過程。

Equals(Object)

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

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

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

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

(繼承來源 MarshalByRefObject)
GetReaderForMessage(SoapClientMessage, Int32)

傳回 XmlReader,它是使用 Stream 參數的 SoapClientMessage 屬性初始化。

GetService(Type)

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

(繼承來源 Component)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
GetWebRequest(Uri)

為指定的 uri 建立 WebRequest

GetWebResponse(WebRequest)

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

(繼承來源 HttpWebClientProtocol)
GetWebResponse(WebRequest, IAsyncResult)

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

(繼承來源 HttpWebClientProtocol)
GetWriterForMessage(SoapClientMessage, Int32)

傳回 XmlWriter,它是使用 Stream 參數的 SoapClientMessage 屬性初始化。

InitializeLifetimeService()
已過時。

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

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

使用 SOAP 同步叫用 XML Web Service 方法。

InvokeAsync(String, Object[], SendOrPostCallback)

非同步叫用指定的方法。

InvokeAsync(String, Object[], SendOrPostCallback, Object)

非同步叫用指定的方法。

MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
MemberwiseClone(Boolean)

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

(繼承來源 MarshalByRefObject)
ToString()

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

(繼承來源 Component)

事件

Disposed

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

(繼承來源 Component)

適用於

執行緒安全性

此型別具備執行緒安全。

另請參閱