HttpGetClientProtocol 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
這是使用 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
- 繼承
-
HttpGetClientProtocol
範例
以下範例是由 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 |
|---|---|
| Disposed |
當元件被呼叫方法 Dispose() 時會發生。 (繼承來源 Component) |