HttpPostClientProtocol 类

定义

使用 HTTP-POST 协议的 XML Web services 客户端代理的基类。

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

示例

以下示例是由下面的 XML Web 服务的 Wsdl.exe 实用工具 Math 生成的代理类。 代理类派生自 HttpPostClientProtocol抽象 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::HttpPostClientProtocol
{
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::HtmlFormParameterWriter::typeid)]
   [returnvalue:System::Xml::Serialization::XmlRootAttribute("snippet1>",Namespace="http://www.contoso.com/",IsNullable=false)]
   int Add( String^ num1, String^ num2 )
   {
      array<Object^>^temp2 = {num1,num2};
      return  *dynamic_cast<int^>(this->Invoke( "Add", (String::Concat( this->Url, "/Add" )), temp2 ));
   }

   [System::Diagnostics::DebuggerStepThroughAttribute]
   System::IAsyncResult^ BeginAdd( String^ num1, String^ num2, System::AsyncCallback^ callback, Object^ asyncState )
   {
      array<Object^>^temp3 = {num1,num2};
      return this->BeginInvoke( "Add", (this->Url + "/Add" ), temp3, 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.HttpPostClientProtocol
{
    [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.HtmlFormParameterWriter))]
    [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.HttpPostClientProtocol
    
    <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.HtmlFormParameterWriter))>  _
    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-POST 协议时,默认情况下参数使用 URL 编码规则在 HTTP 正文中编码,并使用纯 XML 作为响应。 此协议使用派生自 MimeFormatter 对参数进行编码并将值返回为标准 MIME 格式的类。 要使用的编码器在服务说明中指定。

如果要使用 ASP.NET 生成 XML Web 服务客户端,则需要为要调用的 XML Web 服务创建间接或直接派WebClientProtocol生的代理类。 当 XML Web 服务客户端使用 HTTP 调用时,派生代理类,而代理类又派生自WebClientProtocol该代理类HttpSimpleClientProtocol

HttpGetClientProtocolHttpPostClientProtocol 派生自 HttpSimpleClientProtocol,支持分别使用 HTTP-GET 和 HTTP-POST 调用 XML Web 服务方法。 使用 SOAP 调用 XML Web 服务的客户端应派生自 SoapHttpClientProtocol.

有关生成代理类的详细信息,请参阅 创建 XML Web 服务代理

构造函数

HttpPostClientProtocol()

初始化 HttpPostClientProtocol 类的新实例。

属性

AllowAutoRedirect

获取或设置客户端是否自动跟随服务器重定向。

(继承自 HttpWebClientProtocol)
CanRaiseEvents

获取一个指示组件是否可以引发事件的值。

(继承自 Component)
ClientCertificates

获取客户证书集合。

(继承自 HttpWebClientProtocol)
ConnectionGroupName

获取或设置请求的连接组的名称。

(继承自 WebClientProtocol)
Container

获取包含 IContainerComponent

(继承自 Component)
CookieContainer

获取或设置 Cookie 集合。

(继承自 HttpWebClientProtocol)
Credentials

获取或设置 XML Web services 客户端身份验证的安全凭据。

(继承自 WebClientProtocol)
DesignMode

获取一个值,用以指示 Component 当前是否处于设计模式。

(继承自 Component)
EnableDecompression

获取或设置一个值,该值指示是否为此 HttpWebClientProtocol 启用压缩。

(继承自 HttpWebClientProtocol)
Events

获取附加到此 Component 的事件处理程序的列表。

(继承自 Component)
PreAuthenticate

获取或设置是否启用了预身份验证。

(继承自 WebClientProtocol)
Proxy

获取或设置用于通过防火墙进行 XML Web services 请求的代理信息。

(继承自 HttpWebClientProtocol)
RequestEncoding

用于对 XML Web services 发出客户端请求的 Encoding

(继承自 WebClientProtocol)
Site

获取或设置 ComponentISite

(继承自 Component)
Timeout

指示 XML Web services 客户端等待同步 XML Web services 请求完成的时间(以毫秒计)的回复。

(继承自 WebClientProtocol)
UnsafeAuthenticatedConnectionSharing

获取或设置一个值,它指示客户端使用 NTLM 身份验证连接到承载 XML Web services 的 Web 服务器时,是否启用连接共享。

(继承自 HttpWebClientProtocol)
Url

获取或设置客户端正在请求的 XML Web services 的基 URL。

(继承自 WebClientProtocol)
UseDefaultCredentials

获取或设置一个值,该值指示是否将 Credentials 属性设置为 DefaultCredentials 属性的值。

(继承自 WebClientProtocol)
UserAgent

获取或设置随每个请求发送的用户代理标头的值。

(继承自 HttpWebClientProtocol)

方法

Abort()

取消对 XML Web services 方法的请求。

(继承自 WebClientProtocol)
BeginInvoke(String, String, Object[], AsyncCallback, Object)

开始异步调用 XML Web services 的方法。

(继承自 HttpSimpleClientProtocol)
CancelAsync(Object)

取消对 XML Web services 方法的异步调用,除非已完成该调用。

(继承自 HttpWebClientProtocol)
CreateObjRef(Type)

创建一个对象,该对象包含生成用于与远程对象进行通信的代理所需的全部相关信息。

(继承自 MarshalByRefObject)
Dispose()

释放由 Component 使用的所有资源。

(继承自 Component)
Dispose(Boolean)

释放由 Component 占用的非托管资源,还可以另外再释放托管资源。

(继承自 Component)
EndInvoke(IAsyncResult)

完成使用 HTTP 对 XML Web services 方法进行的异步调用。

(继承自 HttpSimpleClientProtocol)
Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetLifetimeService()
已过时。

检索控制此实例的生存期策略的当前生存期服务对象。

(继承自 MarshalByRefObject)
GetService(Type)

返回一个对象,该对象表示由 Component 或它的 Container 提供的服务。

(继承自 Component)
GetType()

获取当前实例的 Type

(继承自 Object)
GetWebRequest(Uri)

为指定的 URI 创建一个 WebRequest 实例。

GetWebResponse(WebRequest)

将同步请求中的响应返回给 XML Web services 方法。

(继承自 HttpWebClientProtocol)
GetWebResponse(WebRequest, IAsyncResult)

将异步请求中的响应返回给 XML Web services 方法。

(继承自 HttpWebClientProtocol)
InitializeLifetimeService()
已过时。

获取生存期服务对象来控制此实例的生存期策略。

(继承自 MarshalByRefObject)
Invoke(String, String, Object[])

使用 HTTP 调用 XML Web services 方法。

(继承自 HttpSimpleClientProtocol)
InvokeAsync(String, String, Object[], SendOrPostCallback)

异步调用指定的方法。

(继承自 HttpSimpleClientProtocol)
InvokeAsync(String, String, Object[], SendOrPostCallback, Object)

在维护关联状态的同时,异步调用指定的方法。

(继承自 HttpSimpleClientProtocol)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
MemberwiseClone(Boolean)

创建当前 MarshalByRefObject 对象的浅表副本。

(继承自 MarshalByRefObject)
ToString()

返回包含 Component 的名称的 String(如果有)。 不应重写此方法。

(继承自 Component)

事件

Disposed

在通过调用 Dispose() 方法释放组件时发生。

(继承自 Component)

适用于

另请参阅