HttpWebClientProtocol Class

Definition

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
public abstract class HttpWebClientProtocol : System.Web.Services.Protocols.WebClientProtocol
[System.Runtime.InteropServices.ComVisible(true)]
public abstract class HttpWebClientProtocol : System.Web.Services.Protocols.WebClientProtocol
type HttpWebClientProtocol = class
    inherit WebClientProtocol
[<System.Runtime.InteropServices.ComVisible(true)>]
type HttpWebClientProtocol = class
    inherit WebClientProtocol
Public MustInherit Class HttpWebClientProtocol
Inherits WebClientProtocol
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 allows the server to automatically redirect the client to other sites. 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>
   

Remarks

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. The properties map to properties found on HttpWebRequest.

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. 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 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. For example, use the Proxy property for calling XML Web services through a firewall. Many of these properties are used to initialize the HttpWebRequest that makes the Web request.

SoapHttpClientProtocol, HttpGetClientProtocol, and HttpPostClientProtocol derive directly or indirectly from HttpWebClientProtocol to provide support for SOAP, HTTP-GET and HTTP-POST respectively.

Constructors

HttpWebClientProtocol()

Initializes a new instance of the HttpWebClientProtocol class.

Properties

AllowAutoRedirect

Gets or sets whether the client automatically follows server redirects.

CanRaiseEvents

Gets a value indicating whether the component can raise an event.

(Inherited from Component)
ClientCertificates

Gets the collection of client certificates.

ConnectionGroupName

Gets or sets the name of the connection group for the request.

(Inherited from WebClientProtocol)
Container

Gets the IContainer that contains the Component.

(Inherited from Component)
CookieContainer

Gets or sets the collection of cookies.

Credentials

Gets or sets security credentials for XML Web service client authentication.

(Inherited from WebClientProtocol)
DesignMode

Gets a value that indicates whether the Component is currently in design mode.

(Inherited from Component)
EnableDecompression

Gets or sets a value that indicates whether decompression is enabled for this HttpWebClientProtocol.

Events

Gets the list of event handlers that are attached to this Component.

(Inherited from Component)
PreAuthenticate

Gets or sets whether pre-authentication is enabled.

(Inherited from WebClientProtocol)
Proxy

Gets or sets proxy information for making an XML Web service request through a firewall.

RequestEncoding

The Encoding used to make the client request to the XML Web service.

(Inherited from WebClientProtocol)
Site

Gets or sets the ISite of the Component.

(Inherited from Component)
Timeout

Indicates the time an XML Web service client waits for the reply to a synchronous XML Web service request to arrive (in milliseconds).

(Inherited from WebClientProtocol)
UnsafeAuthenticatedConnectionSharing

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

Gets or sets the base URL of the XML Web service the client is requesting.

(Inherited from WebClientProtocol)
UseDefaultCredentials

Gets or sets a value that indicates whether to set the Credentials property to the value of the DefaultCredentials property.

(Inherited from WebClientProtocol)
UserAgent

Gets or sets the value for the user agent header that is sent with each request.

Methods

Abort()

Cancels a request to an XML Web service method.

(Inherited from WebClientProtocol)
CancelAsync(Object)

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.

(Inherited from MarshalByRefObject)
Dispose()

Releases all resources used by the Component.

(Inherited from Component)
Dispose(Boolean)

Releases the unmanaged resources used by the Component and optionally releases the managed resources.

(Inherited from Component)
Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GenerateXmlMappings(Type, 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)

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.

(Inherited from Object)
GetLifetimeService()
Obsolete.

Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
GetService(Type)

Returns an object that represents a service provided by the Component or by its Container.

(Inherited from Component)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
GetWebRequest(Uri)

Creates a WebRequest for the specified URI.

GetWebResponse(WebRequest, IAsyncResult)

Returns a response from an asynchronous request to an XML Web service method.

GetWebResponse(WebRequest)

Returns a response from a synchronous request to an XML Web service method.

InitializeLifetimeService()
Obsolete.

Obtains a lifetime service object to control the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
MemberwiseClone(Boolean)

Creates a shallow copy of the current MarshalByRefObject object.

(Inherited from MarshalByRefObject)
ToString()

Returns a String containing the name of the Component, if any. This method should not be overridden.

(Inherited from Component)

Events

Disposed

Occurs when the component is disposed by a call to the Dispose() method.

(Inherited from Component)

Applies to

Thread Safety

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 gets 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.

See also