Freigeben über


HttpWebClientProtocol-Klasse

Die Basisklasse für alle XML-Webdienst-Clientproxys, die das HTTP-Übertragungsprotokoll verwenden.

Namespace: System.Web.Services.Protocols
Assembly: System.Web.Services (in system.web.services.dll)

Syntax

'Declaration
<ComVisibleAttribute(True)> _
Public MustInherit Class HttpWebClientProtocol
    Inherits WebClientProtocol
'Usage
Dim instance As HttpWebClientProtocol
[ComVisibleAttribute(true)] 
public abstract class HttpWebClientProtocol : WebClientProtocol
[ComVisibleAttribute(true)] 
public ref class HttpWebClientProtocol abstract : public WebClientProtocol
/** @attribute ComVisibleAttribute(true) */ 
public abstract class HttpWebClientProtocol extends WebClientProtocol
ComVisibleAttribute(true) 
public abstract class HttpWebClientProtocol extends WebClientProtocol

Hinweise

Die Eigenschaften in dieser Klasse werden verwendet, um das Verhalten des HTTP-Anforderungsobjekts zu steuern, das zum Übertragen der XML-Webdienstanforderung und -antwort verwendet wird. Die Eigenschaften stimmen mit den Eigenschaften in HttpWebRequest überein.

Um über HTTP mit einem XML-Webdienst zu kommunizieren, müssen Sie eine Proxyklasse erstellen, die direkt oder indirekt vom HttpWebClientProtocol für den XML-Webdienst abgeleitet ist. Sie müssen die Proxyklasse nicht manuell erstellen, sondern können das Tool Wsdl.exe verwenden, um eine Proxyklasse für die Dienstbeschreibung eines bestimmten XML-Webdiensts zu erstellen.

Da HttpWebClientProtocol die Basisklasse für alle Proxyklassen darstellt, befinden sich ihre Eigenschaften in den Proxyklassen. Diese Eigenschaften sind besonders für die Steuerung des Anforderungsverhaltens des zugrunde liegenden Transports hilfreich. Sie können beispielsweise mithilfe der Proxy-Eigenschaft XML-Webdienste über eine Firewall aufrufen. Viele dieser Eigenschaften werden zum Initialisieren der HttpWebRequest verwendet, die die Webanforderung ausführt.

SoapHttpClientProtocol, HttpGetClientProtocol und HttpPostClientProtocol sind direkt oder indirekt aus dem HttpWebClientProtocol abgeleitet, sodass sie SOAP, HTTP-GET bzw. HTTP-POST unterstützen.

Beispiel

Das folgende Beispiel ist eine ASP.NET-Web Form, die den XML-Webdienst Math aufruft. Innerhalb der EnterBtn_Click-Funktion kann der Server mithilfe des Web Forms den Client automatisch zu anderen Sites umleiten. Er legt auch die Anmeldeinformationen für die Clientauthentifizierung, die Proxyeinstellungen, die Anforderungscodierung und das Timeout für die Anforderung vor dem Aufruf der XML-Webdienstmethode fest.

<%@ 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>
   
<%@ 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>
   

Vererbungshierarchie

System.Object
   System.MarshalByRefObject
     System.ComponentModel.Component
       System.Web.Services.Protocols.WebClientProtocol
        System.Web.Services.Protocols.HttpWebClientProtocol
           System.Web.Services.Discovery.DiscoveryClientProtocol
           System.Web.Services.Protocols.HttpSimpleClientProtocol
           System.Web.Services.Protocols.SoapHttpClientProtocol

Threadsicherheit

Die Eigenschaften dieser Klasse werden für jeden Aufruf der XML-Webdienstmethode in eine neue Instanz eines WebRequest-Objekts kopiert. Es ist zwar möglich, XML-Webdienstmethoden für ein und dieselbe WebClientProtocol-Instanz gleichzeitig über unterschiedliche Threads aufzurufen, es erfolgt jedoch keine Synchronisierung, um sicherzustellen, dass ein einheitlicher Snapshot der Eigenschaften an das WebRequest-Objekt übertragen wird. Wenn Sie die Eigenschaften ändern und gleichzeitig mehrere Methodenaufrufe über verschiedene Threads durchführen müssen, sollten Sie daher eine andere Instanz des XML-Webdienstproxys verwenden oder selbst dafür sorgen, dass eine Synchronisierung erfolgt.

Plattformen

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

.NET Compact Framework

Unterstützt in: 2.0, 1.0

Siehe auch

Referenz

HttpWebClientProtocol-Member
System.Web.Services.Protocols-Namespace
WebClientProtocol
WebRequest
SoapHttpClientProtocol
HttpGetClientProtocol-Klasse
HttpPostClientProtocol-Klasse