WebClientProtocol 类
定义
指定使用 ASP.NET 创建的所有 XML Web services 客户端代理的基类。Specifies the base class for all XML Web service client proxies created using ASP.NET.
public ref class WebClientProtocol abstract : System::ComponentModel::Component
public abstract class WebClientProtocol : System.ComponentModel.Component
[System.Runtime.InteropServices.ComVisible(true)]
public abstract class WebClientProtocol : System.ComponentModel.Component
type WebClientProtocol = class
inherit Component
[<System.Runtime.InteropServices.ComVisible(true)>]
type WebClientProtocol = class
inherit Component
Public MustInherit Class WebClientProtocol
Inherits Component
- 继承
- 派生
- 属性
示例
下面的示例是 ASP.NET Web 窗体,它调用名为的 XML Web service Math 。The following example is an ASP.NET Web Form, which calls an XML Web service named Math. 在 EnterBtn_Click 函数中,Web 窗体在调用远程 XML Web service 方法之前在代理类上设置代理信息和客户端凭据。Within the EnterBtn_Click function, the Web Form sets proxy information and client credentials on the proxy class prior to calling the remote XML Web service method.
重要
此示例具有一个接受用户输入的文本框,这是一个潜在的安全威胁。This example has a text box that accepts user input, which is a potential security threat. 默认情况下,ASP.NET 网页验证用户输入是否不包含脚本或 HTML 元素。By default, ASP.NET Web pages validate that user input does not include script or HTML elements. 有关详细信息,请参阅脚本侵入概述。For more information, see Script Exploits Overview.
<%@ 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();
// Set the client-side credentials using the Credentials property.
ICredentials credentials = new NetworkCredential("Joe","mydomain","password");
math.Credentials = credentials;
// Do not allow the server to redirect the request.
math.AllowAutoRedirect = false;
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()
' Set the client-side credentials using the Credentials property.
Dim credentials As New NetworkCredential("Joe", "password", "mydomain")
math.Credentials = credentials
' Do not allow the server to redirect the request.
math.AllowAutoRedirect = False
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>
注解
类的属性 WebClientProtocol 用于控制传输 XML Web service 请求和响应时使用的传输行为。The properties of the WebClientProtocol class are used to control the behavior of the transport used to transmit the XML Web service request and response. 此类的属性映射到上找到的属性 WebRequest 。The properties on this class map to properties found on WebRequest. 派生自的类的实例( WebRequest 如 HttpWebRequest )用作使用 ASP.NET 创建的 XML Web services 的传输机制。Instances of classes deriving from WebRequest, such as HttpWebRequest, are used as the transport mechanism for XML Web services created using ASP.NET.
若要与 XML Web service 通信,您必须创建一个间接或直接从中派生的代理类, WebClientProtocol 以便要调用的 XML Web service。To communicate with an XML Web service, you must create a proxy class deriving indirectly or directly from WebClientProtocol for the XML Web service you want to call. 您可以使用 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. 由于 WebClientProtocol 是你的客户端代理的基类,因此你将在代理类中找到其属性。Since WebClientProtocol is the base class for your client proxy, you will find its properties on your proxy classes. 这些属性对于控制基础传输的请求行为很有用。These properties are useful for controlling the request behavior of the underlying transport. 例如,使用 Credentials 属性调用通过身份验证的 XML Web 服务。For instance, use the Credentials property for calling authenticated XML Web services. 许多 WebClientProtocol 属性用于初始化 WebRequest 用于发出 Web 请求的对象。Many of the WebClientProtocol properties are used to initialize the WebRequest object that is used to make the Web request.
构造函数
| WebClientProtocol() |
初始化 WebClientProtocol 类的新实例。Initializes a new instance of the WebClientProtocol class. |
属性
| CanRaiseEvents |
获取一个指示组件是否可以引发事件的值。Gets a value indicating whether the component can raise an event. (继承自 Component) |
| ConnectionGroupName |
获取或设置请求的连接组的名称。Gets or sets the name of the connection group for the request. |
| Container |
获取包含 IContainer 的 Component。Gets the IContainer that contains the Component. (继承自 Component) |
| Credentials |
获取或设置 XML Web services 客户端身份验证的安全凭据。Gets or sets security credentials for XML Web service client authentication. |
| DesignMode |
获取一个值,用以指示 Component 当前是否处于设计模式。Gets a value that indicates whether the Component is currently in design mode. (继承自 Component) |
| Events |
获取附加到此 Component 的事件处理程序的列表。Gets the list of event handlers that are attached to this Component. (继承自 Component) |
| PreAuthenticate |
获取或设置是否启用了预身份验证。Gets or sets whether pre-authentication is enabled. |
| RequestEncoding |
用于对 XML Web services 发出客户端请求的 Encoding。The Encoding used to make the client request to the XML Web service. |
| Site |
获取或设置 Component 的 ISite。Gets 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). |
| Url |
获取或设置客户端正在请求的 XML Web services 的基 URL。Gets or sets the base URL of the XML Web service the client is requesting. |
| UseDefaultCredentials |
获取或设置一个值,该值指示是否将 Credentials 属性设置为 DefaultCredentials 属性的值。Gets or sets a value that indicates whether to set the Credentials property to the value of the DefaultCredentials property. |
方法
| Abort() |
取消对 XML Web services 方法的请求。Cancels a request to an XML Web service method. |
| AddToCache(Type, Object) |
向缓存添加客户端协议处理程序的实例。Add an instance of the client protocol handler to the cache. |
| 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) |
| GetFromCache(Type) |
获取缓存中的客户端协议处理程序的实例。Gets an instance of a client protocol handler from the cache. |
| 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() |
获取当前实例的 Type。Gets the Type of the current instance. (继承自 Object) |
| GetWebRequest(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. 这一受保护的方法由 XML Web services 客户端基础结构调用来获取来自异步 XML Web services 请求的响应。This protected method is called by the XML Web service client infrastructure to get the response from an asynchronous XML Web service request. |
| 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() |
返回包含 Component 的名称的 String(如果有)。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) |
适用于
线程安全性
WebRequest对于每个 XML Web service 方法调用,此类的属性都将复制到对象的新实例中。The properties on this class are copied into a new instance of a WebRequest object for each XML Web service method call. 尽管可以同时从不同线程的同一实例调用 XML Web service 方法 WebClientProtocol ,但没有完成同步,以确保将属性的一致快照传输到 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 will get 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.