SoapHttpClientProtocol.BeginInvoke Metod
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Startar en asynkron anrop av en XML-webbtjänstmetod med 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
Parametrar
- methodName
- String
Namnet på XML-webbtjänstmetoden i den härledda klass som anropar BeginInvoke(String, Object[], AsyncCallback, Object) metoden.
- parameters
- Object[]
En matris med objekt som innehåller parametrarna som ska skickas till XML-webbtjänsten. Ordningen på värdena i matrisen motsvarar ordningen på parametrarna i den härledda klassens anropande metod.
- callback
- AsyncCallback
Ombudet som ska anropas när den asynkrona anropet är klar. Om callback är nullanropas inte ombudet.
- asyncState
- Object
Extra information som tillhandahålls av anroparen.
Returer
En IAsyncResult som skickas till EndInvoke(IAsyncResult) metoden för att hämta returvärdena från fjärrmetodanropet.
Undantag
Begäran nådde serverdatorn, men bearbetades inte.
Begäran var inte giltig för objektets aktuella tillstånd.
Ett fel uppstod vid åtkomst till nätverket.
Exempel
Följande kodexempel är en proxyklass som genereras av verktyget Web Services Description Language (Wsdl.exe) för Math XML-webbtjänsten.
BeginAdd I metoden för proxyklassen BeginInvoke startar metoden en asynkron anrop till Add XML-webbtjänstmetoden.
#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
Följande kodexempel är Math XML-webbtjänsten, från vilken den föregående proxyklassen skapades.
<%@ 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
Kommentarer
Vanligtvis anropar BeginInvoke du inte metoden direkt, såvida du inte skapade en egen proxyklass för en XML-webbtjänst.
En proxyklass som genereras av verktyget Web Services Description Language (Wsdl.exe) från en tjänstbeskrivning exponerar XML-webbtjänstmetoderna som namn som härleds från proxyklassen för att anropa XML-webbtjänstmetoderna synkront. Om du vill anropa XML-webbtjänstmetoderna asynkront läggs ytterligare två metoder till i proxyklassen för varje XML-webbtjänstmetod, en med Begin prefixet lagt till i namnet på XML-webbtjänstmetoden och en med prefixet End tillagt.
Proxyklassen BeginInvoke anropar metoden för att starta ett asynkront anrop till XML-webbtjänstmetoden. Om en XML-webbtjänst till exempel exponerar en XML-webbtjänstmetod med namnet Addinnehåller proxyklassen en metod med namnet BeginAdd, för att starta ett anrop till XML-webbtjänstmetoden. I koden för BeginAddgörs ett anrop till BeginInvoke metoden och resultatet placeras i den förväntade returtypen för Add.
methodName Används för att hitta anpassade attribut som kan ha lagts till i metoden, till exempel SoapDocumentMethodAttribute.
SoapDocumentMethodAttribute innehåller ytterligare information om den härledda metoden som krävs för SOAP-protokollet.
asyncState skickas till callback och ingår i IAsyncResult som returneras från BeginInvoke metoden. Parametern asyncState kan användas för att skicka information om kontexten för det asynkrona anropet, som anges i parametern callback , till ombudet som hanterar resultatet.