SoapHttpClientProtocol.BeginInvoke Metodo

Definizione

Avvia una chiamata asincrona di un metodo del servizio Web XML tramite SOAP.

protected:
 IAsyncResult ^ BeginInvoke(System::String ^ methodName, cli::array <System::Object ^> ^ parameters, AsyncCallback ^ callback, System::Object ^ asyncState);
protected IAsyncResult BeginInvoke (string methodName, object[] parameters, AsyncCallback callback, object asyncState);
member this.BeginInvoke : string * obj[] * AsyncCallback * obj -> IAsyncResult
Protected Function BeginInvoke (methodName As String, parameters As Object(), callback As AsyncCallback, asyncState As Object) As IAsyncResult

Parametri

methodName
String

Nome del metodo del servizio Web XML nella classe derivata che chiama il metodo BeginInvoke(String, Object[], AsyncCallback, Object).

parameters
Object[]

Matrice di oggetti contenente i parametri da passare al servizio Web XML. L'ordine dei valori nella matrice corrisponde all'ordine dei parametri nel metodo chiamante della classe derivata.

callback
AsyncCallback

Delegato da richiamare una volta completata la chiamata asincrona. Se callback è null, il delegato non viene chiamato.

asyncState
Object

Informazioni aggiuntive fornite dal chiamante.

Restituisce

Oggetto IAsyncResult che viene passato al metodo EndInvoke(IAsyncResult) per ottenere i valori restituiti dalla chiamata remota del metodo.

Eccezioni

La richiesta ha raggiunto il computer server ma non è stata elaborata con esito positivo.

La richiesta non era valida per lo stato corrente dell'oggetto.

Si è verificato un errore durante l'accesso alla rete.

Esempio

L'esempio di codice seguente è una classe proxy generata dallo strumento Web Services Description Language (Wsdl.exe) per il Math servizio Web XML. All'interno del BeginAdd metodo della classe proxy, il BeginInvoke metodo avvia una chiamata asincrona al metodo del Add servizio Web XML.

#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="http://www.contoso.com/")]
   public ref class MyMath: public System::Web::Services::Protocols::SoapHttpClientProtocol
   {
   public:

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


      [System::Diagnostics::DebuggerStepThroughAttribute]
      [System::Web::Services::Protocols::SoapDocumentMethodAttribute("http://www.contoso.com/Add",
      RequestNamespace="http://www.contoso.com/",ResponseNamespace="http://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 ]);
      }

   };

}


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="http://www.contoso.com/")]
    public class MyMath : System.Web.Services.Protocols.SoapHttpClientProtocol {

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

        [System.Diagnostics.DebuggerStepThroughAttribute()]
        [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://www.contoso.com/Add", RequestNamespace="http://www.contoso.com/", ResponseNamespace="http://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]));
        }
    }
}

Option Strict On
Option Explicit On

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]:="http://www.contoso.com/")>  _
    Public Class MyMath
        Inherits System.Web.Services.Protocols.SoapHttpClientProtocol
        
        <System.Diagnostics.DebuggerStepThroughAttribute()>  _
        Public Sub New()
            MyBase.New
            Me.Url = "http://www.contoso.com/math.asmx"
        End Sub
        
        <System.Diagnostics.DebuggerStepThroughAttribute(),  _
         System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://www.contoso.com/Add", RequestNamespace:="http://www.contoso.com/", ResponseNamespace:="http://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

L'esempio di codice seguente è il Math servizio Web XML, da cui è stata creata la classe proxy precedente.

<%@ WebService Language="C#" Class="MyMath"%>
 using System.Web.Services;
 using System;
 
 [WebService(Namespace="http://www.contoso.com/")] 
 public class MyMath {

    [ WebMethod ]
    public int Add(int num1, int num2) {
        return num1+num2;
    }
 }
<%@ WebService Language="VB" Class="MyMath"%>
Imports System.Web.Services
Imports System

<WebService(Namespace:="http://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

Commenti

In genere, il metodo non viene chiamato BeginInvoke direttamente, a meno che non si compilasse una classe proxy personalizzata per un servizio Web XML.

Una classe proxy generata dallo strumento Web Services Description Language (Wsdl.exe) da una descrizione del servizio espone i metodi del servizio Web XML come nomi derivati dalla classe proxy per chiamare i metodi del servizio Web XML in modo sincrono. Per chiamare i metodi del servizio Web XML in modo asincrono, vengono aggiunti due metodi aggiuntivi alla classe proxy per ogni metodo del servizio Web XML, uno con il Begin prefisso aggiunto al nome del metodo del servizio Web XML e uno con il End prefisso aggiunto.

La classe proxy chiama il BeginInvoke metodo per avviare una chiamata asincrona al metodo del servizio Web XML. Ad esempio, se un servizio Web XML espone un metodo di servizio Web XML denominato Add, la classe proxy contiene un metodo denominato BeginAdd, per avviare una chiamata al metodo del servizio Web XML. All'interno del codice per BeginAdd, viene effettuata una chiamata al BeginInvoke metodo e i risultati vengono inseriti nel tipo restituito previsto per Add.

Viene methodName utilizzato per trovare gli attributi personalizzati che possono essere stati aggiunti al metodo, ad esempio SoapDocumentMethodAttribute. SoapDocumentMethodAttribute fornisce informazioni aggiuntive sul metodo derivato necessario per il protocollo SOAP.

asyncState viene passato in callback e viene incluso nell'oggetto IAsyncResult restituito dal BeginInvoke metodo . Il asyncState parametro può essere usato per passare informazioni sul contesto della chiamata asincrona, specificata nel callback parametro , al delegato che gestisce il risultato.

Si applica a

Vedi anche