HttpSimpleClientProtocol 类

定义

表示用于使用简单的 HTTP-GET 和 HTTP-POST 协议绑定与 XML Web services 进行通信的基类。Represents the base class for communicating with an XML Web service using the simple HTTP-GET and HTTP-POST protocols bindings.

public ref class HttpSimpleClientProtocol abstract : System::Web::Services::Protocols::HttpWebClientProtocol
[System.Runtime.InteropServices.ComVisible(true)]
public abstract class HttpSimpleClientProtocol : System.Web.Services.Protocols.HttpWebClientProtocol
type HttpSimpleClientProtocol = class
    inherit HttpWebClientProtocol
Public MustInherit Class HttpSimpleClientProtocol
Inherits HttpWebClientProtocol
继承
派生
属性

示例

下面的代码示例是由 wsdl.exe 为Math以下 XML Web service 生成的代理类。The following code example is a proxy class generated by Wsdl.exe for the Math XML Web service below. 代理类派生HttpGetClientProtocol自抽象类, 后者派生自抽象HttpSimpleClientProtocol类。The proxy class derives from HttpGetClientProtocol, which derives from the abstract HttpSimpleClientProtocol class.

#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 service。The following code example is the Math XML Web service, from which the preceding proxy class was created.

#using <System.EnterpriseServices.dll>
#using <System.Web.Services.dll>

using namespace System::Web::Services;
using namespace System;
public ref class Math
{
public:

   [WebMethod]
   int Add( int num1, int num2 )
   {
      return num1 + num2;
   }

};

using System.Web.Services;
using System;
 
public class Math
{
    [WebMethod]
    public int Add(int num1, int num2)
    {
        return num1 + num2;
    }
}
Imports System.Web.Services

Public Class Math
    <WebMethod()> _
    Public Function Add(num1 As Integer, num2 As Integer)As Integer
    
        Return num1 + num2
    End Function
    
End Class

注解

此类通过使用编码器将参数编码并将值返回到常见 MIME 格式, 来指定用于通过 HTTP 与 XML Web service 进行通信的大部分实现。This class specifies most of the implementation for communicating with an XML Web service over HTTP using encoders to encode the parameters and return values into common MIME formats. 这些编码器派生自MimeFormatter类。These encoders derive from the MimeFormatter class. 默认情况下, 从HttpSimpleClientProtocol使用 application/x-url 编码 MIME 类型的参数和纯 XML 中的响应, 派生的代理类将参数编码。By default, a proxy class deriving from HttpSimpleClientProtocol encodes parameters using the application/x-www-form-urlencoded MIME type and the response in plain XML. 可以使用HttpMethodAttribute特性指定自定义 mime 格式化程序, 但是, 不支持将其集成到服务说明和代理生成。Custom mime formatters can be specified using the HttpMethodAttribute attribute, however, there is no support for integrating this into a service description and proxy generation.

Notes to Inheritors:重写此类时, 可以在派生类中引入特定于特定类型的 XML Web service 的方法。Notes to Inheritors: When you override this class, you can introduce methods in the derived class that are specific to a particular type of an XML Web service. 方法只是捕获参数, 并调用基类来完成与站点的通信工作。The methods simply capture the parameters, and call the base class to do the work of communicating with the site. 如果引入的方法是异步的, 则BeginInvoke调用EndInvoke和方法。If the introduced methods are asynchronous, call the BeginInvoke and EndInvoke methods. 如果引入的方法是同步的, 请Invoke调用方法。If the introduced methods are synchronous, call the Invoke method. 重写的构造函数通常Url将属性设置为 XML Web service 方法的 URI。The overridden constructor typically sets the Url property to the URI of the XML Web service method.

Web 服务描述语言工具 (wsdl.exe) 为给定的服务说明生成的HttpSimpleClientProtocol派生类。The Web Services Description Language tool (Wsdl.exe) generates derived classes of HttpSimpleClientProtocol for a given Service Description.

构造函数

HttpSimpleClientProtocol()

初始化 HttpSimpleClientProtocol 类的新实例。Initializes a new instance of the HttpSimpleClientProtocol class.

属性

AllowAutoRedirect

获取或设置客户端是否自动跟随服务器重定向。Gets or sets whether the client automatically follows server redirects.

(继承自 HttpWebClientProtocol)
CanRaiseEvents

获取一个指示组件是否可以引发事件的值。Gets a value indicating whether the component can raise an event.

(继承自 Component)
ClientCertificates

获取客户证书集合。Gets the collection of client certificates.

(继承自 HttpWebClientProtocol)
ConnectionGroupName

获取或设置请求的连接组的名称。Gets or sets the name of the connection group for the request.

(继承自 WebClientProtocol)
Container

获取 IContainer,它包含 ComponentGets the IContainer that contains the Component.

(继承自 Component)
CookieContainer

获取或设置 Cookie 集合。Gets or sets the collection of cookies.

(继承自 HttpWebClientProtocol)
Credentials

获取或设置 XML Web services 客户端身份验证的安全凭据。Gets or sets security credentials for XML Web service client authentication.

(继承自 WebClientProtocol)
DesignMode

获取一个值,用以指示 Component 当前是否处于设计模式。Gets a value that indicates whether the Component is currently in design mode.

(继承自 Component)
EnableDecompression

获取或设置一个值,该值指示是否为此 HttpWebClientProtocol 启用压缩。Gets or sets a value that indicates whether decompression is enabled for this HttpWebClientProtocol.

(继承自 HttpWebClientProtocol)
Events

获取附加到此 Component 的事件处理程序的列表。Gets the list of event handlers that are attached to this Component.

(继承自 Component)
PreAuthenticate

获取或设置是否启用了预身份验证。Gets or sets whether pre-authentication is enabled.

(继承自 WebClientProtocol)
Proxy

获取或设置用于通过防火墙进行 XML Web services 请求的代理信息。Gets or sets proxy information for making an XML Web service request through a firewall.

(继承自 HttpWebClientProtocol)
RequestEncoding

用于对 XML Web services 发出客户端请求的 EncodingThe Encoding used to make the client request to the XML Web service.

(继承自 WebClientProtocol)
Site

获取或设置 ISiteComponentGets or sets the ISite of the Component.

(继承自 Component)
Timeout

指示 XML Web services 客户端等待同步 XML Web services 请求完成的时间(以毫秒计)的回复。Indicates the time an XML Web service client waits for the reply to a synchronous XML Web service request to arrive (in milliseconds).

(继承自 WebClientProtocol)
UnsafeAuthenticatedConnectionSharing

获取或设置一个值,它指示客户端使用 NTLM 身份验证连接到承载 XML Web services 的 Web 服务器时,是否启用连接共享。Gets or sets a value that indicates whether connection sharing is enabled when the client uses NTLM authentication to connect to the Web server that hosts the XML Web service.

(继承自 HttpWebClientProtocol)
Url

获取或设置客户端正在请求的 XML Web services 的基 URL。Gets or sets the base URL of the XML Web service the client is requesting.

(继承自 WebClientProtocol)
UseDefaultCredentials

获取或设置一个值,该值指示是否将 Credentials 属性设置为 DefaultCredentials 属性的值。Gets or sets a value that indicates whether to set the Credentials property to the value of the DefaultCredentials property.

(继承自 WebClientProtocol)
UserAgent

获取或设置随每个请求发送的用户代理标头的值。Gets or sets the value for the user agent header that is sent with each request.

(继承自 HttpWebClientProtocol)

方法

Abort()

取消对 XML Web services 方法的请求。Cancels a request to an XML Web service method.

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

开始异步调用 XML Web services 的方法。Starts an asynchronous invocation of a method of an XML Web service.

CancelAsync(Object)

取消对 XML Web services 方法的异步调用,除非已完成该调用。Cancels an asynchronous call to an XML Web service method, unless the call has already completed.

(继承自 HttpWebClientProtocol)
CreateObjRef(Type)

创建一个对象,该对象包含生成用于与远程对象进行通信的代理所需的全部相关信息。Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(继承自 MarshalByRefObject)
Dispose()

释放 Component 使用的所有资源。Releases all resources used by the Component.

(继承自 Component)
Dispose(Boolean)

释放 Component 使用的非托管资源,并选择性地释放托管资源。Releases the unmanaged resources used by the Component and optionally releases the managed resources.

(继承自 Component)
EndInvoke(IAsyncResult)

完成使用 HTTP 对 XML Web services 方法进行的异步调用。Completes asynchronous invocation of an XML Web service method using HTTP.

Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetHashCode()

用作默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetLifetimeService()

检索控制此实例的生存期策略的当前生存期服务对象。Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(继承自 MarshalByRefObject)
GetService(Type)

返回一个对象,该对象表示由 Component 或它的 Container 提供的服务。Returns an object that represents a service provided by the Component or by its Container.

(继承自 Component)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
GetWebRequest(Uri)

为指定的 URI 创建一个 WebRequestCreates a WebRequest for the specified URI.

(继承自 HttpWebClientProtocol)
GetWebResponse(WebRequest)

将同步请求中的响应返回给 XML Web services 方法。Returns a response from a synchronous request to an XML Web service method.

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

将异步请求中的响应返回给 XML Web services 方法。Returns a response from an asynchronous request to an XML Web service method.

(继承自 HttpWebClientProtocol)
InitializeLifetimeService()

获取生存期服务对象来控制此实例的生存期策略。Obtains a lifetime service object to control the lifetime policy for this instance.

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

使用 HTTP 调用 XML Web services 方法。Invokes an XML Web service method using HTTP.

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

异步调用指定的方法。Invokes the specified method asynchronously.

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

在维护关联状态的同时,异步调用指定的方法。Invokes the specified method asynchronously while maintaining an associated state.

MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
MemberwiseClone(Boolean)

创建当前 MarshalByRefObject 对象的浅表副本。Creates a shallow copy of the current MarshalByRefObject object.

(继承自 MarshalByRefObject)
ToString()

返回包含 String 的名称的 Component(如果有)。Returns a String containing the name of the Component, if any. 不应重写此方法。This method should not be overridden.

(继承自 Component)

事件

Disposed

当通过调用 Dispose() 方法释放组件时发生。Occurs when the component is disposed by a call to the Dispose() method.

(继承自 Component)

适用于

线程安全性

此类型是线程安全的。This type is thread safe.

另请参阅