HttpWebClientProtocol 类

定义

表示所有使用 HTTP 传输协议的 XML Web services 客户端代理的基类。Represents the base class for all XML Web service client proxies that use the HTTP transport protocol.

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

示例

下面的示例是 ASP.NET Web 窗体,它调用名为Math的 XML Web service。The following example is an ASP.NET Web Form, which calls an XML Web service named Math. EnterBtn_Click在函数中,Web 窗体允许服务器将客户端自动重定向到其他站点。Within the EnterBtn_Click function, the Web Form allows the server to automatically redirect the client to other sites. 它还在调用 XML Web service 方法之前设置客户端身份验证凭据、代理设置、请求编码和请求超时。It also sets client authentication credentials, proxy settings, the request encoding and the time out for the request before calling the XML Web service method.

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Net" %>

<html>
    <script language="C#" runat="server">
       void EnterBtn_Click(Object Src, EventArgs E) 
          {
             MyMath.Math math = new MyMath.Math();

             // Allow the server to redirect the request.
             math.AllowAutoRedirect = true;

             // Set the client-side credentials using the Credentials property.
             ICredentials credentials =
                new NetworkCredential("Joe","password","mydomain");
             math.Credentials = credentials;

             // Set the proxy server to proxyserver, set the port to 80, and specify to bypass
             // the proxy server for local addresses.
             IWebProxy proxyObject = new WebProxy("http://proxyserver:80",true);
             math.Proxy = proxyObject;

             // Set the encoding to utf-8.
             math.RequestEncoding = System.Text.Encoding.UTF8;

             // Set the time out to 15 seconds
             math.Timeout = 15000;

             int total = math.Add(Convert.ToInt32(Num1.Text),
                Convert.ToInt32(Num2.Text));
             Total.Text = "Total: " + total.ToString();
         }
 
    </script>
 
    <body>
       <form action="MathClient.aspx" runat=server>
           
          Enter the two numbers you want to add and then press the Total button.
          <p>
          Number 1: <asp:textbox id="Num1" runat=server/>  +
          Number 2: <asp:textbox id="Num2" runat=server/> =
          <asp:button text="Total" Onclick="EnterBtn_Click" runat=server/>
          <p>
          <asp:label id="Total"  runat=server/>
          
       </form>
    </body>
 </html>
   
<%@ Page Language="VB" %>
<%@ Import Namespace="System.Net" %>

<html>
    <script language="VB" runat="server">

    Sub EnterBtn_Click(Src As Object, E As EventArgs)
        Dim math As New MyMath.Math()
        
        ' Allow the server to redirect the request.
        math.AllowAutoRedirect = True
        
        ' Set the client-side credentials using the Credentials property.
        Dim credentials = New NetworkCredential("Joe", "password", "mydomain")
        math.Credentials = credentials
        
        ' Set the proxy server to proxyserver, set the port to 80 and specify to bypass
        ' the proxy server for local addresses.
        Dim proxyObject = New WebProxy("http://proxyserver:80", True)
        math.Proxy = proxyObject
        
        ' Set the encoding to utf-8.
        math.RequestEncoding = System.Text.Encoding.UTF8
        
        ' Set the time out to 15 seconds.
        math.Timeout = 15000
        
        Dim iTotal As Integer = math.Add(Convert.ToInt32(Num1.Text), _
           Convert.ToInt32(Num2.Text))
        Total.Text = "Total: " & iTotal.ToString()
    End Sub
 
    </script>
 
    <body>
       <form action="MathClient.aspx" runat=server>
           
          Enter the two numbers you want to add and then press the Total button.
          <p>
          Number 1: <asp:textbox id="Num1" runat=server/>  +
          Number 2: <asp:textbox id="Num2" runat=server/> =
          <asp:button text="Total" Onclick="EnterBtn_Click" runat=server/>
          <p>
          <asp:label id="Total"  runat=server/>
          
       </form>
    </body>
 </html>
   

注解

此类的属性用于控制 HTTP 请求对象的行为,该对象用于传输 XML Web service 请求和响应。The properties on this class are used to control the behavior of the HTTP request object used to transmit the XML Web service request and response. 属性将映射到中的HttpWebRequest属性。The properties map to properties found on HttpWebRequest.

若要使用 HTTP 与 XML Web service 通信,您必须创建一个间接或直接从HttpWebClientProtocol XML Web service 派生的代理类。To communicate with an XML Web service using HTTP, you must create a proxy class deriving indirectly or directly from HttpWebClientProtocol for the XML Web service. 您可以使用 Wsdl.exe 工具创建给定 XML Web service 的服务说明的代理类,而不是手动创建代理类。Instead of creating the proxy class manually, you can use the Wsdl.exe tool to create a proxy class for a given XML Web service's service description.

由于 Httpwebclientprotocol 派生是所有代理类的基类,因此其属性在代理类中。Since HttpWebClientProtocol is the base class for all proxy classes, its properties are on your proxy classes. 这些属性对于控制基础传输的请求行为很有用。These properties are useful for controlling the request behavior of the underlying transport. 例如,使用Proxy属性通过防火墙调用 XML Web 服务。For example, use the Proxy property for calling XML Web services through a firewall. 其中的许多属性用于初始化发出 Web 请求HttpWebRequest的。Many of these properties are used to initialize the HttpWebRequest that makes the Web request.

SoapHttpClientProtocolHttpGetClientProtocolHttpPostClientProtocolHttpWebClientProtocol直接或间接派生,分别为 SOAP、http GET 和 http POST 提供支持。SoapHttpClientProtocol, HttpGetClientProtocol, and HttpPostClientProtocol derive directly or indirectly from HttpWebClientProtocol to provide support for SOAP, HTTP-GET and HTTP-POST respectively.

构造函数

HttpWebClientProtocol()

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

属性

AllowAutoRedirect

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

CanRaiseEvents

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

(继承自 Component)
ClientCertificates

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

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.

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.

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.

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.

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.

方法

Abort()

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

(继承自 WebClientProtocol)
CancelAsync(Object)

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

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)
Equals(Object)

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

(继承自 Object)
GenerateXmlMappings(Type, ArrayList)

获取由指定类型公开的每个 XML Web services 方法的 XmlMembersMapping,然后将映射存储在指定的 ArrayList 中。Gets the XmlMembersMapping for each XML Web service method exposed by the specified type, and stores the mappings in the specified ArrayList.

GenerateXmlMappings(Type[], ArrayList)

获取由指定类型公开的每个 XML Web services 方法的 XmlMembersMapping,然后将映射存储在指定的 ArrayList 中,同时也存储在此方法返回的 Hashtable 中。Gets the XmlMembersMapping for each XML Web service method exposed by the specified types, and stores the mappings in the specified ArrayList, as well as in a Hashtable that this method returns.

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.

GetWebResponse(WebRequest)

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

GetWebResponse(WebRequest, IAsyncResult)

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

InitializeLifetimeService()

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

(继承自 MarshalByRefObject)
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)

适用于

线程安全性

对于每个 XML Web service 方法调用,此类的属性都将WebRequest复制到对象的新实例中。The properties on this class are copied into a new instance of a WebRequest object for each XML Web service method call. 尽管可以同时从不同的线程对同一WebClientProtocol实例调用 XML Web service 方法,但没有完成同步以确保将属性的一致快照传输WebRequest到对象。While you can call XML Web service methods on the same WebClientProtocol instance from different threads at the same time, there is no synchronization done to ensure that a consistent snapshot of the properties gets transferred to the WebRequest object. 因此,如果需要修改属性并从不同线程进行并发方法调用,则应使用 XML Web service 代理的不同实例,或提供自己的同步。Therefore, if you need to modify the properties and make concurrent method calls from different threads you should use a different instance of the XML Web service proxy or provide your own synchronization.

另请参阅