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
示例
以下示例是由下面的 XML Web 服务 Wsdl.exe Math 生成的代理类。 代理类派生自 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 Web 服务的客户端应派生自 SoapHttpClientProtocol.
有关生成代理类的详细信息,请参阅 创建 XML Web 服务代理。
构造函数
| 名称 | 说明 |
|---|---|
| HttpGetClientProtocol() |
初始化 HttpGetClientProtocol 类的新实例。 |
属性
方法
活动
| 名称 | 说明 |
|---|---|
| Disposed |
当组件通过对方法的调用 Dispose() 释放时发生。 (继承自 Component) |