WebClientProtocol Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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
- Inheritance
- Derived
- Attributes
Examples
The following example is an ASP.NET Web Form, which calls an XML Web service named Math. 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.
Important
This example has a text box that accepts user input, which is a potential security threat. 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>
Remarks
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. The properties on this class map to properties found on WebRequest. Instances of classes deriving from WebRequest, such as HttpWebRequest, are used as the transport mechanism for XML Web services created using ASP.NET.
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. 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. 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. For instance, use the Credentials property for calling authenticated XML Web services. Many of the WebClientProtocol properties are used to initialize the WebRequest object that is used to make the Web request.
Constructors
| Name | Description |
|---|---|
| WebClientProtocol() |
Initializes a new instance of the WebClientProtocol class. |
Properties
| Name | Description |
|---|---|
| CanRaiseEvents |
Gets a value indicating whether the component can raise an event. (Inherited from Component) |
| ConnectionGroupName |
Gets or sets the name of the connection group for the request. |