Freigeben über


SoapHttpClientProtocol.Invoke-Methode

Ruft eine XML-Webdienstmethode unter Verwendung von SOAP synchron auf.

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

Syntax

'Declaration
Protected Function Invoke ( _
    methodName As String, _
    parameters As Object() _
) As Object()
'Usage
Dim methodName As String
Dim parameters As Object()
Dim returnValue As Object()

returnValue = Me.Invoke(methodName, parameters)
protected Object[] Invoke (
    string methodName,
    Object[] parameters
)
protected:
array<Object^>^ Invoke (
    String^ methodName, 
    array<Object^>^ parameters
)
protected Object[] Invoke (
    String methodName, 
    Object[] parameters
)
protected function Invoke (
    methodName : String, 
    parameters : Object[]
) : Object[]

Parameter

  • methodName
    Der Name der XML-Webdienstmethode.
  • 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.

Rückgabewert

Ein Array von Objekten mit dem Rückgabewert und allen reference-Parametern bzw. out-Parametern der abgeleiteten Klassenmethode.

Ausnahmen

Ausnahmetyp Bedingung

SoapException

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

Hinweise

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

Eine durch das WSDL-Tool (Wsdl.exe) für einen XML-Webdienst generierte Proxyklasse macht die XML-Webdienstmethoden als Namen aus der Proxyklasse verfügbar. Die Proxyklasse ruft die Invoke-Methode auf, um einen XML-Webdienstmethodenaufruf aufzurufen. Wenn ein XML-Webdienst beispielsweise die XML-Webdienstmethode Add verfügbar macht, enthält die Proxyklasse ebenfalls die Methode Add. Innerhalb von Code für die Add-Methode in der Proxyklasse erfolgt ein synchroner Aufruf an die XML-Webdienstmethode über die Invoke-Methode. Die Ergebnisse werden anschließend in den erwarteten Rückgabewert für Add positioniert.

Mithilfe des methodName-Parameters werden die benutzerdefinierten Attribute ermittelt, die in die Methode eingefügt wurden, z. B. SoapDocumentMethodAttribute. SoapDocumentMethodAttribute stellt zusätzliche Informationen zur abgeleiteten und für das SOAP-Protokoll erforderlichen Methode bereit.

Beispiel

Im folgenden Codebeispiel wird eine von Wsdl.exe generierte Proxyklasse für den Math-XML-Webdienst veranschaulicht. Innerhalb der Add-Methode der Proxyklasse ruft die Invoke-Methode die Add-XML-Webdienstmethode auf.

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^>^temp0 = {num1,num2};
         array<Object^>^results = this->Invoke( "Add", temp0 );
         return  *dynamic_cast<int^>(results[ 0 ]);
      }


      [System::Diagnostics::DebuggerStepThroughAttribute]
      System::IAsyncResult^ BeginAdd( int num1, int num2, System::AsyncCallback^ callback, Object^ asyncState )
      {
         array<Object^>^temp1 = {num1,num2};
         return this->BeginInvoke( "Add", temp1, 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
SoapDocumentMethodAttribute-Klasse
WebClientProtocol