Freigeben über


SoapHttpClientProtocol.BeginInvoke-Methode

Startet den asynchronen Aufruf einer XML-Webdienstmethode unter Verwendung von SOAP.

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

Syntax

'Declaration
Protected Function BeginInvoke ( _
    methodName As String, _
    parameters As Object(), _
    callback As AsyncCallback, _
    asyncState As Object _
) As IAsyncResult
'Usage
Dim methodName As String
Dim parameters As Object()
Dim callback As AsyncCallback
Dim asyncState As Object
Dim returnValue As IAsyncResult

returnValue = Me.BeginInvoke(methodName, parameters, callback, asyncState)
protected IAsyncResult BeginInvoke (
    string methodName,
    Object[] parameters,
    AsyncCallback callback,
    Object asyncState
)
protected:
IAsyncResult^ BeginInvoke (
    String^ methodName, 
    array<Object^>^ parameters, 
    AsyncCallback^ callback, 
    Object^ asyncState
)
protected IAsyncResult BeginInvoke (
    String methodName, 
    Object[] parameters, 
    AsyncCallback callback, 
    Object asyncState
)
protected function BeginInvoke (
    methodName : String, 
    parameters : Object[], 
    callback : AsyncCallback, 
    asyncState : Object
) : IAsyncResult

Parameter

  • methodName
    Der Name der XML-Webdienstmethode in der abgeleiteten Klasse, die die BeginInvoke-Methode aufruft.
  • parameters
    Ein Array von Objekten mit den Parametern, die an den XML-Webdienst übergeben werden sollen. Die Reihenfolge der Werte im Array entspricht der Reihenfolge der Parameter in der Aufrufmethode der abgeleiteten Klasse.
  • callback
    Der Delegat, der aufgerufen werden soll, wenn der asynchrone Aufruf abgeschlossen ist. Wenn callback auf NULL (Nothing in Visual Basic) festgelegt ist, wird der Delegat nicht aufgerufen.
  • asyncState
    Zusätzliche vom Aufrufer bereitgestellte Informationen.

Rückgabewert

Ein IAsyncResult, das an die EndInvoke-Methode übergeben wird, um die Rückgabewerte des Remotemethodenaufrufs abzurufen.

Ausnahmen

Ausnahmetyp Bedingung

SoapException

Die Anforderung hat den Servercomputer erreicht, wurde jedoch nicht erfolgreich verarbeitet.

Hinweise

Sie rufen die BeginInvoke-Methode i. d. R. nur dann direkt auf, wenn Sie eine eigene Proxyklasse für einen XML-Webdienst erstellen.

Eine durch das WSDL-Tool (Web Services Description Language – Wsdl.exe) einer Dienstbeschreibung generierte Proxyklasse macht die XML-Webdienstmethoden als Namen verfügbar, die aus der Proxyklasse zum synchronen Aufrufen der XML-Webdienstmethoden abgeleitet werden. Zum asynchronen Aufrufen der XML-Webdienstmethoden werden der Proxyklasse für jede XML-Webdienstmethode zwei zusätzliche Proxyklassen hinzugefügt: eine Proxyklasse, bei der das Begin-Präfix dem Namen der XML-Webdienstmethode hinzugefügt wird, sowie eine mit hinzugefügtem End-Präfix.

Die Proxyklasse ruft zum Starten eines asynchronen Aufrufs an die XML-Webdienstmethode die BeginInvoke-Methode auf. Wenn ein XML-Webdienst beispielsweise die XML-Webdienstmethode Add verfügbar macht, enthält die Proxyklasse zum Starten eines Aufrufs an die XML-Webdienstmethode die Methode BeginAdd. Innerhalb von Code für BeginAdd wird die BeginInvoke-Methode aufgerufen, und die Ergebnisse werden in den für Add erwarteten Rückgabetyp positioniert.

Mithilfe von methodName werden die möglicherweise der Methode hinzugefügten benutzerdefinierten Attribute ermittelt, z. B. SoapDocumentMethodAttribute. SoapDocumentMethodAttribute stellt zusätzliche Informationen zur abgeleiteten und für das SOAP-Protokoll erforderlichen Methode bereit.

asyncState wird an callback übergeben und in das von der BeginInvoke-Methode zurückgegebene IAsyncResult eingefügt. Über den asyncState-Parameter können Informationen zum Kontext des asynchronen Aufrufs, der im callback-Parameter angegeben ist, an den Delegaten übergeben und das Ergebnis behandelt werden.

Beispiel

Im folgenden Codebeispiel wird eine vom WSDL-Tool (Wsdl.exe) generierte Proxyklasse für den Math-XML-Webdienst veranschaulicht. Innerhalb der BeginAdd-Methode der Proxyklasse startet die BeginInvoke-Methode einen asynchronen Aufruf an die Add-XML-Webdienstmethode.

Option Strict On
Option Explicit On

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

Namespace MyMath
    
    <System.Web.Services.WebServiceBindingAttribute(Name:="MyMathSoap", [Namespace]:="https://www.contoso.com/")>  _
    Public Class MyMath
        Inherits System.Web.Services.Protocols.SoapHttpClientProtocol
        
        <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.SoapDocumentMethodAttribute("https://www.contoso.com/Add", RequestNamespace:="https://www.contoso.com/", ResponseNamespace:="https://www.contoso.com/", Use:=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle:=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)>  _
        Public Function Add(ByVal num1 As Integer, ByVal num2 As Integer) As Integer
            Dim results() As Object = Me.Invoke("Add", New Object() {num1, num2})
            Return CType(results(0),Integer)
        End Function
        
        <System.Diagnostics.DebuggerStepThroughAttribute()>  _
        Public Function BeginAdd(ByVal num1 As Integer, ByVal num2 As Integer, ByVal callback As System.AsyncCallback, ByVal asyncState As Object) As System.IAsyncResult
            Return Me.BeginInvoke("Add", New Object() {num1, num2}, callback, asyncState)
        End Function
        
        <System.Diagnostics.DebuggerStepThroughAttribute()>  _
        Public Function EndAdd(ByVal asyncResult As System.IAsyncResult) As Integer
            Dim results() As Object = Me.EndInvoke(asyncResult)
            Return CType(results(0),Integer)
        End Function
    End Class
End Namespace
namespace MyMath {
    using System.Diagnostics;
    using System.Xml.Serialization;
    using System;
    using System.Web.Services.Protocols;
    using System.Web.Services;
    
    
    [System.Web.Services.WebServiceBindingAttribute(Name="MyMathSoap", Namespace="https://www.contoso.com/")]
    public class MyMath : System.Web.Services.Protocols.SoapHttpClientProtocol {
        
        [System.Diagnostics.DebuggerStepThroughAttribute()]
        public MyMath() {
            this.Url = "https://www.contoso.com/math.asmx";
        }
        
        [System.Diagnostics.DebuggerStepThroughAttribute()]
        [System.Web.Services.Protocols.SoapDocumentMethodAttribute("https://www.contoso.com/Add", RequestNamespace="https://www.contoso.com/", ResponseNamespace="https://www.contoso.com/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
        public int Add(int num1, int num2) {
            object[] results = this.Invoke("Add", new object[] {num1,
                        num2});
            return ((int)(results[0]));
        }
        
        [System.Diagnostics.DebuggerStepThroughAttribute()]
        public System.IAsyncResult BeginAdd(int num1, int num2, System.AsyncCallback callback, object asyncState) {
            return this.BeginInvoke("Add", new object[] {num1,
                        num2}, callback, asyncState);
        }
        
        [System.Diagnostics.DebuggerStepThroughAttribute()]
        public int EndAdd(System.IAsyncResult asyncResult) {
            object[] results = this.EndInvoke(asyncResult);
            return ((int)(results[0]));
        }
    }
}
#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;

namespace MyMath
{

   [System::Web::Services::WebServiceBindingAttribute(Name="MyMathSoap",Namespace="https://www.contoso.com/")]
   public ref class MyMath: public System::Web::Services::Protocols::SoapHttpClientProtocol
   {
   public:

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


      [System::Diagnostics::DebuggerStepThroughAttribute]
      [System::Web::Services::Protocols::SoapDocumentMethodAttribute("https://www.contoso.com/Add",
      RequestNamespace="https://www.contoso.com/",ResponseNamespace="https://www.contoso.com/",
      Use=System::Web::Services::Description::SoapBindingUse::Literal,
      ParameterStyle=System::Web::Services::Protocols::SoapParameterStyle::Wrapped)]
      int Add( int num1, int num2 )
      {
         array<Object^>^temp1 = {num1,num2};
         array<Object^>^results = this->Invoke( "Add", temp1 );
         return  *dynamic_cast<int^>(results[ 0 ]);
      }


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


      [System::Diagnostics::DebuggerStepThroughAttribute]
      int EndAdd( System::IAsyncResult^ asyncResult )
      {
         array<Object^>^results = this->EndInvoke( asyncResult );
         return  *dynamic_cast<int^>(results[ 0 ]);
      }

   };

}
package MyMath; 

import System.Diagnostics.*;
import System.Xml.Serialization.*;
import System.*;
import System.Web.Services.Protocols.*;
import System.Web.Services.*;

/** @attribute System.Web.Services.WebServiceBindingAttribute(Name = 
    "MyMathSoap", Namespace = "https://www.contoso.com/")
 */

public class MyMath extends System.Web.Services.Protocols.SoapHttpClientProtocol
{
    /** @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.SoapDocumentMethodAttribute(
         "https://www.contoso.com/Add", RequestNamespace = 
        "https://www.contoso.com/", ResponseNamespace = 
        "https://www.contoso.com/", Use = 
        System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle 
        = System.Web.Services.Protocols.SoapParameterStyle.Wrapped)
     */

    public int Add(int num1, int num2)
    {
        Object results[] = this.Invoke("Add", new Object[] { 
            (Int32)num1, (Int32)num2 });
        return (int)((Int32)results.get_Item(0));
    } //Add

    /** @attribute System.Diagnostics.DebuggerStepThroughAttribute()
     */

    public System.IAsyncResult BeginAdd(int num1, int num2, 
        System.AsyncCallback callback, Object asyncState)
    {
        return this.BeginInvoke("Add", new Object[] { 
            (Int32)num1, (Int32)num2 }, callback, asyncState);
    } //BeginAdd

    /** @attribute System.Diagnostics.DebuggerStepThroughAttribute()
     */

    public int EndAdd(System.IAsyncResult asyncResult)
    {
        Object results[] = this.EndInvoke(asyncResult);
        return (int)((Int32)results.get_Item(0));
    } //EndAdd
} //MyMath

Im folgenden Codebeispiel wird der Math-XML-Webdienst veranschaulicht, aus dem die vorherige Proxyklasse erstellt wurde.

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

<WebService(Namespace:="https://www.contoso.com/")> _
Public Class MyMath
    <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="MyMath"%>
 using System.Web.Services;
 using System;
 
 [WebService(Namespace="https://www.contoso.com/")] 
 public class MyMath {
      [ WebMethod ]
      public int Add(int num1, int num2) {
          return num1+num2;
          }
 }
<%@ WebService Language="VJ#" Class="MyMath"%>
import System.Web.Services .* ;
import System .* ;


/** @attribute WebService(Namespace = "https://www.contoso.com/")
* */
public class MyMath
{
   /** @attribute WebMethod()
   * */
   public int Add(int num1, int num2) 
   {
      return num1 + num2 ;
   } 
} 

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

SoapHttpClientProtocol-Klasse
SoapHttpClientProtocol-Member
System.Web.Services.Protocols-Namespace
IAsyncResult
AsyncCallback
EndInvoke
SoapDocumentMethodAttribute-Klasse
WebClientProtocol