SoapHttpClientProtocol 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
指定使用 SOAP 時代理所衍生的類別用戶端。
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
- 繼承
- 屬性
範例
以下程式碼範例是由 Wsdl.exe Math 為 XML Web 服務產生的代理類別。 代理類由 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 服務,前述代理類別即由此產生。
Important
此範例中有一個文字框可接受使用者輸入,這可能構成安全威脅。 預設情況下,ASP.NET 網頁會驗證使用者輸入中不包含腳本或 HTML 元素。 欲了解更多資訊,請參閱 腳本漏洞概述。
<%@ 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 代理類別。 當 XML Web 服務客戶端使用 SOAP 呼叫時,代理類別必須從 SoapHttpClientProtocol衍生出 ,而 又從 衍生出 HttpWebClientProtocol。 HttpWebClientProtocol,又從 推導出 WebClientProtocol。
要與 XML Web 服務通訊,請建立一個代理類別,該類別可間接或直接衍生於 WebClientProtocol 你想呼叫的 XML Web 服務。 與其手動建立代理類別,不如使用 Web Services Description Language 工具(Wsdl.exe)為特定 XML Web 服務的服務描述建立代理類別。 當為 SOAP 協定產生代理類別時,透過該 Invoke 方法同步呼叫 XML Web 服務方法,而非同步呼叫則使用 BeginInvoke 該方法與 方法 EndInvoke 。
給繼承者的注意事項
當你覆寫這個類別時,可以在派生類別中引入特定類型的 XML Web 服務方法。 這些方法會擷取參數並呼叫基底類別,來執行與 XML Web 服務通訊的工作。 若引入的方法為非同步,則呼叫該 BeginInvoke(String, Object[], AsyncCallback, Object) 方法與該 EndInvoke(IAsyncResult) 方法。 如果引入的方法是同步的,則呼叫該 Invoke(String, Object[]) 方法。 覆寫後的建構子通常將屬性設定 Url 為 XML Web 服務方法的 URL。
建構函式
| 名稱 | Description |
|---|---|
| SoapHttpClientProtocol() |
初始化 SoapHttpClientProtocol 類別的新執行個體。 |
屬性
| 名稱 | 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 | (繼承來源 Component) |
| SoapVersion |
取得或設定用於向 XML Web 服務提出 SOAP 請求的 SOAP 協定版本。 |
| Timeout |
表示 XML Web 服務用戶端等候回復至同步 XML Web 服務要求的時間(以毫秒為單位)。 (繼承來源 WebClientProtocol) |
| UnsafeAuthenticatedConnectionSharing |
當用戶端使用 NTLM 認證連接承載 XML 網路服務的 Web 伺服器時,會取得或設定一個值,指示是否啟用連線共享。 (繼承來源 HttpWebClientProtocol) |
| Url |
取得或設定用戶端要求之 XML Web 服務的基底 URL。 (繼承來源 WebClientProtocol) |
| UseDefaultCredentials |
取得或設定值,這個值表示是否要將 Credentials 屬性設定為 DefaultCredentials 屬性的值。 (繼承來源 WebClientProtocol) |
| UserAgent |
取得或設定每次請求中傳送的使用者代理標頭值。 (繼承來源 HttpWebClientProtocol) |
方法
事件
| 名稱 | Description |
|---|---|
| Disposed |
當元件被呼叫方法 Dispose() 時會發生。 (繼承來源 Component) |
適用於
執行緒安全性
此類型是安全線程。