Freigeben über


HttpPostClientProtocol-Klasse

Die Basisklasse für XML-Webdienst-Clientproxys, die das HTTP-POST-Protokoll verwenden.

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

Syntax

'Declaration
Public Class HttpPostClientProtocol
    Inherits HttpSimpleClientProtocol
'Usage
Dim instance As HttpPostClientProtocol
public class HttpPostClientProtocol : HttpSimpleClientProtocol
public ref class HttpPostClientProtocol : public HttpSimpleClientProtocol
public class HttpPostClientProtocol extends HttpSimpleClientProtocol
public class HttpPostClientProtocol extends HttpSimpleClientProtocol

Hinweise

Wenn ein XML-Webdienstclient das HTTP-POST-Protokoll verwendet, werden Parameter standardmäßig innerhalb des HTTP-Hauptteils unter Verwendung der URL-Codierungsregeln codiert, und für die Antwort wird reines XML verwendet. Dieses Protokoll verwendet von MimeFormatter abgeleitete Klassen, um Parameter und Rückgabewerte in standardmäßigen MIME-Formaten zu codieren. Die zu verwendenden Encoder werden in der Dienstbeschreibung angegeben.

Wenn Sie einen XML-Webdienstclient unter Verwendung von ASP.NET erstellen, muss für den aufzurufenden XML-Webdienst eine Proxyklasse erstellt werden, die direkt oder indirekt von WebClientProtocol abgeleitet ist. Wenn der XML-Webdienstclient den Aufruf über HTTP durchführt, leiten Sie die Proxyklasse vom HttpSimpleClientProtocol ab, das wiederum vom WebClientProtocol abgeleitet ist.

HttpGetClientProtocol und HttpPostClientProtocol sind vom HttpSimpleClientProtocol abgeleitet und stellen die Unterstützung für das Aufrufen einer XML-Webdienstmethode unter Verwendung des HTTP-GET-Protokolls bzw. des HTTP-POST-Protokolls bereit. Clients, die einen XML-Webdienst mit SOAP aufrufen, werden vom SoapHttpClientProtocol abgleitet.

Ausführliche Informationen zum Erstellen einer Proxyklasse finden Sie unter Erstellen eines XML-Webdienstproxys.

Beispiel

Das folgende Beispiel stellt eine vom Dienstprogramm Wsdl.exe für den unten aufgeführten Math-XML-Webdienst generierte Proxyklasse dar. Die Proxyklasse wird vom HttpPostClientProtocol abgeleitet, das wiederum von der abstrakten HttpSimpleClientProtocol-Klasse abgeleitet ist.

Option Strict On
Option Explicit On

Imports System
Imports System.Diagnostics
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Xml.Serialization

Public Class MyMath
    Inherits System.Web.Services.Protocols.HttpPostClientProtocol
    
    <System.Diagnostics.DebuggerStepThroughAttribute()>  _
    Public Sub New()
        MyBase.New
        Me.Url = "https://www.contoso.com/math.asmx"
    End Sub
    
    <System.Diagnostics.DebuggerStepThroughAttribute(),  _
     System.Web.Services.Protocols.HttpMethodAttribute(GetType(System.Web.Services.Protocols.XmlReturnReader), GetType(System.Web.Services.Protocols.HtmlFormParameterWriter))>  _
    Public Function Add(ByVal num1 As String, ByVal num2 As String) As <System.Xml.Serialization.XmlRootAttribute("int", [Namespace]:="https://www.contoso.com/", IsNullable:=false)> Integer
        Return CType(Me.Invoke("Add", (Me.Url + "/Add"), New Object() {num1, num2}),Integer)
    End Function
    
    <System.Diagnostics.DebuggerStepThroughAttribute()>  _
    Public Function BeginAdd(ByVal num1 As String, ByVal num2 As String, ByVal callback As System.AsyncCallback, ByVal asyncState As Object) As System.IAsyncResult
        Return Me.BeginInvoke("Add", (Me.Url + "/Add"), New Object() {num1, num2}, callback, asyncState)
    End Function
    
    <System.Diagnostics.DebuggerStepThroughAttribute()>  _
    Public Function EndAdd(ByVal asyncResult As System.IAsyncResult) As Integer
        Return CType(Me.EndInvoke(asyncResult),Integer)
    End Function
End Class
using System.Diagnostics;
using System.Xml.Serialization;
using System;
using System.Web.Services.Protocols;
using System.Web.Services;


public class MyMath : System.Web.Services.Protocols.HttpPostClientProtocol {
    
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    public MyMath() {
        this.Url = "https://www.contoso.com/math.asmx";
    }
    
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.Web.Services.Protocols.HttpMethodAttribute(typeof(System.Web.Services.Protocols.XmlReturnReader), typeof(System.Web.Services.Protocols.HtmlFormParameterWriter))]
    [return: System.Xml.Serialization.XmlRootAttribute("int", Namespace="https://www.contoso.com/", IsNullable=false)]
    public int Add(string num1, string num2) {
        return ((int)(this.Invoke("Add", (this.Url + "/Add"), new object[] {num1,
                    num2})));
    }
    
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    public System.IAsyncResult BeginAdd(string num1, string num2, System.AsyncCallback callback, object asyncState) {
        return this.BeginInvoke("Add", (this.Url + "/Add"), new object[] {num1,
                    num2}, callback, asyncState);
    }
    
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    public int EndAdd(System.IAsyncResult asyncResult) {
        return ((int)(this.EndInvoke(asyncResult)));
    }
}
#using <System.Web.Services.dll>
#using <System.Xml.dll>
#using <System.dll>

using namespace System::Diagnostics;
using namespace System::Xml::Serialization;
using namespace System;
using namespace System::Web::Services::Protocols;
using namespace System::Web::Services;

public ref class MyMath: public System::Web::Services::Protocols::HttpPostClientProtocol
{
public:

   [System::Diagnostics::DebuggerStepThroughAttribute]
   MyMath()
   {
      this->Url = "https://www.contoso.com/math.asmx";
   }

   [System::Diagnostics::DebuggerStepThroughAttribute]
   [System::Web::Services::Protocols::HttpMethodAttribute(System::Web::Services::Protocols::XmlReturnReader::typeid,
   System::Web::Services::Protocols::HtmlFormParameterWriter::typeid)]
   [returnvalue:System::Xml::Serialization::XmlRootAttribute("snippet1>",Namespace="https://www.contoso.com/",IsNullable=false)]
   int Add( String^ num1, String^ num2 )
   {
      array<Object^>^temp2 = {num1,num2};
      return  *dynamic_cast<int^>(this->Invoke( "Add", (String::Concat( this->Url, "/Add" )), temp2 ));
   }

   [System::Diagnostics::DebuggerStepThroughAttribute]
   System::IAsyncResult^ BeginAdd( String^ num1, String^ num2, System::AsyncCallback^ callback, Object^ asyncState )
   {
      array<Object^>^temp3 = {num1,num2};
      return this->BeginInvoke( "Add", (this->Url + "/Add" ), temp3, callback, asyncState );
   }

   [System::Diagnostics::DebuggerStepThroughAttribute]
   int EndAdd( System::IAsyncResult^ asyncResult )
   {
      return  *dynamic_cast<int^>(this->EndInvoke( asyncResult ));
   }
};
import System.Diagnostics.*;
import System.Xml.Serialization.*;
import System.*;
import System.Web.Services.Protocols.*;
import System.Web.Services.*;

public class MyMath extends System.Web.Services.Protocols.HttpPostClientProtocol
{      
    /** @attribute System.Diagnostics.DebuggerStepThroughAttribute()
     */
    public MyMath() 
    {
        this.set_Url("https://www.contoso.com/math.asmx");
    } //MyMath   

    /** @attribute System.Diagnostics.DebuggerStepThroughAttribute()
     */
    /** @attribute System.Web.Services.Protocols.HttpMethodAttribute(
        System.Web.Services.Protocols.XmlReturnReader .class,
        System.Web.Services.Protocols.HtmlFormParameterWriter.class)
     */
    public int Add(String num1, String num2)
    {
        return Integer.parseInt(System.Convert.ToString((this.Invoke("Add",
            this.get_Url() + "/Add", new Object[]{num1, num2})))) ;
    } //Add  
   
    /** @attribute System.Diagnostics.DebuggerStepThroughAttribute()
     */
    public System.IAsyncResult BeginAdd(String num1, String num2, 
        System.AsyncCallback callback, Object asyncState)
    {
        return this.BeginInvoke("Add", this.get_Url() + "/Add", 
            new Object[]{num1, num2}, callback, asyncState) ;
    } //BeginAdd  
   
    /** @attribute System.Diagnostics.DebuggerStepThroughAttribute()
     */
    public int EndAdd(System.IAsyncResult asyncResult) {
        return Integer.parseInt(System.Convert.ToString(
            this.EndInvoke(asyncResult)));
    } //EndAdd
} //MyMath

Das folgende Beispiel ist der Math-XML-Webdienst, aus dem die oben genannte Proxyklasse erstellt wurde.

<%@ WebService Language="VB" Class="Math"%>
Imports System.Web.Services
Imports System

Public Class Math
    <WebMethod()> _
    Public Function Add(num1 As Integer, num2 As Integer) As Integer
        Return num1 + num2
    End Function 'Add
End Class 'Math
<%@ WebService Language="C#" Class="Math"%>
 using System.Web.Services;
 using System;
 
 public class Math {
      [ WebMethod ]
      public int Add(int num1, int num2) {
          return num1+num2;
          }
 }
<%@ WebService Language="VJ#" Class="Math"%>

import System.Web.Services.*;
import System.*;

public class Math
{  
   /** @attribute WebMethod()
    */
    public int Add(int num1, int num2)
    {
        return num1 + num2;
    } //Add
} //Math

Vererbungshierarchie

System.Object
   System.MarshalByRefObject
     System.ComponentModel.Component
       System.Web.Services.Protocols.WebClientProtocol
         System.Web.Services.Protocols.HttpWebClientProtocol
           System.Web.Services.Protocols.HttpSimpleClientProtocol
            System.Web.Services.Protocols.HttpPostClientProtocol

Threadsicherheit

Alle öffentlichen statischen (Shared in Visual Basic) Member dieses Typs sind threadsicher. Bei Instanzmembern ist die Threadsicherheit nicht gewährleistet.

Plattformen

Windows 98, Windows 2000 SP4, Windows Millennium Edition, 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

Siehe auch

Referenz

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