Assembly: System.Web.Services (in system.web.services.dll)
'Declaration <ComVisibleAttribute(True)> _ Public MustInherit Class WebClientProtocol Inherits Component 'Usage Dim instance As WebClientProtocol
/** @attribute ComVisibleAttribute(true) */ public abstract class WebClientProtocol extends Component
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.
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.
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 (Visual Studio).
<%@ 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>
The properties on this class are copied into a new instance of a WebRequest object for each XML Web service method call. 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. 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.
Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter EditionThe Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.