Hinweis
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, sich anzumelden oder das Verzeichnis zu wechseln.
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, das Verzeichnis zu wechseln.
Startet den asynchronen Aufruf einer Methode eines XML-Webdiensts.
Namespace: System.Web.Services.Protocols
Assembly: System.Web.Services (in system.web.services.dll)
Syntax
'Declaration
Protected Function BeginInvoke ( _
methodName As String, _
requestUrl As String, _
parameters As Object(), _
callback As AsyncCallback, _
asyncState As Object _
) As IAsyncResult
'Usage
Dim methodName As String
Dim requestUrl As String
Dim parameters As Object()
Dim callback As AsyncCallback
Dim asyncState As Object
Dim returnValue As IAsyncResult
returnValue = Me.BeginInvoke(methodName, requestUrl, parameters, callback, asyncState)
protected IAsyncResult BeginInvoke (
string methodName,
string requestUrl,
Object[] parameters,
AsyncCallback callback,
Object asyncState
)
protected:
IAsyncResult^ BeginInvoke (
String^ methodName,
String^ requestUrl,
array<Object^>^ parameters,
AsyncCallback^ callback,
Object^ asyncState
)
protected IAsyncResult BeginInvoke (
String methodName,
String requestUrl,
Object[] parameters,
AsyncCallback callback,
Object asyncState
)
protected function BeginInvoke (
methodName : String,
requestUrl : String,
parameters : Object[],
callback : AsyncCallback,
asyncState : Object
) : IAsyncResult
Parameter
- methodName
Der Name der XML-Webdienstmethode.
- requestUrl
Der beim Erstellen von WebRequest zu verwendende URL.
- parameters
Ein Array von Objekten mit den Parametern, die an die XML-Webdienstmethode zu übergeben sind. 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 Methodenaufruf abgeschlossen ist. Wenn callback auf NULL (Nothing in Visual Basic) festgelegt ist, wird der Delegat nicht aufgerufen.
- asyncState
Die von einem Client gelieferten zusätzlichen Informationen.
Rückgabewert
Ein IAsyncResult, das an die EndInvoke-Methode übergeben werden kann, um die Rückgabewerte von der XML-Webdienstmethode abzurufen.
Ausnahmen
| Ausnahmetyp | Bedingung |
|---|---|
Die Anforderung hat den Servercomputer erreicht, wurde jedoch nicht erfolgreich verarbeitet. |
Hinweise
Mithilfe des methodName-Parameters können die Typen der Parameter und Rückgabewerte der Methode ermittelt werden, die die BeginInvoke-Methode aufruft. Er wird auch für die Suche nach benutzerdefinierten Attributen verwendet, die der Methode möglicherweise hinzugefügt wurden. SoapDocumentMethodAttribute, SoapRpcMethodAttribute und XmlElementAttribute liefern zusätzliche Informationen zu der abgeleiteten Methode, die für das HTTP-Protokoll erforderlich ist.
asyncState wird an callback übergeben und in das von der BeginInvoke-Methode zurückgegebene IAsyncResult eingefügt. Dies empfiehlt sich beim Übergeben von Informationen aus dem Kontext des asynchronen Aufrufs zur Behandlung des asynchronen Ergebnisses in callback.
Beispiel
Im folgenden Codebeispiel wird ein ASP.NET Web Form veranschaulicht, das einen XML-Webdienst mit dem Namen Math aufruft. Innerhalb der EnterBtn_Click-Funktion startet das Web Form einen asynchronen Aufruf der Add-XML-Webdienstmethode und schließt diesen Aufruf ab.
<%@ Page Language="VB" %>
<html>
<script language="VB" runat="server">
Sub EnterBtn_Click(Src As Object, E As EventArgs)
Dim math As New MyMath.Math()
' Call to Add XML Web service method asynchronously.
Dim result As IAsyncResult = math.BeginAdd(Convert.ToInt32(Num1.Text), Convert.ToInt32(Num2.Text), Nothing, Nothing)
' Wait for the asynchronous call to complete.
result.AsyncWaitHandle.WaitOne()
' Complete the asynchronous call to the Add XML Web service method.
Dim iTotal As Integer = math.EndAdd(result)
Total.Text = "Total: " & iTotal.ToString()
End Sub 'EnterBtn_Click
</script>
<body>
<form action="MathClient.aspx" runat=server>
Enter the two numbers you want to add and then press the Total button.
<p>
Number 1: <asp:textbox id="Num1" runat=server/> +
Number 2: <asp:textbox id="Num2" runat=server/> =
<asp:button text="Total" Onclick="EnterBtn_Click" runat=server/>
<p>
<asp:label id="Total" runat=server/>
</form>
</body>
</html>
<%@ Page Language="C#" %>
<html>
<script language="C#" runat="server">
void EnterBtn_Click(Object Src, EventArgs E)
{
MyMath.Math math = new MyMath.Math();
// Call the Add XML Web service method asynchronously.
IAsyncResult result = math.BeginAdd(Convert.ToInt32(Num1.Text), Convert.ToInt32(Num2.Text), null, null);
// Wait for the asynchronous call to complete.
result.AsyncWaitHandle.WaitOne();
// Complete the asynchronous call to the Add XML Web service method.
int total = math.EndAdd(result);
Total.Text = "Total: " + total.ToString();
}
</script>
<body>
<form action="MathClient.aspx" runat=server>
Enter the two numbers you want to add and then press the Total button.
<p>
Number 1: <asp:textbox id="Num1" runat=server/> +
Number 2: <asp:textbox id="Num2" runat=server/> =
<asp:button text="Total" Onclick="EnterBtn_Click" runat=server/>
<p>
<asp:label id="Total" runat=server/>
</form>
</body>
</html>
Im folgenden Codebeispiel wird eine vom WSDL-Tool (Wsdl.exe) generierte Proxyklasse für den unten aufgeführten Math-XML-Webdienst veranschaulicht. Innerhalb der BeginAdd-Methode der Proxyklasse startet die BeginInvoke-Methode einen asynchronen Aufruf der Add-XML-Webdienstmethode.
Namespace MyMath
<XmlRootAttribute("int", Namespace := "http://MyMath/", IsNullable := False)> _
Public Class Math
Inherits HttpGetClientProtocol
Public Sub New()
Me.Url = "https://www.contoso.com/math.asmx"
End Sub 'New
<HttpMethodAttribute(GetType(XmlReturnReader), GetType(UrlParameterWriter))> _
Public Function Add(num1 As String, num2 As String) As Integer
Return CInt(Me.Invoke("Add", Me.Url + "/Add", New Object() {num1, num2}))
End Function 'Add
Public Function BeginAdd(num1 As String, num2 As String, callback As AsyncCallback, asyncState As Object) As IAsyncResult
Return Me.BeginInvoke("Add", Me.Url + "/Add", New Object() {num1, num2}, callback, asyncState)
End Function 'BeginAdd
Public Function EndAdd(asyncResult As IAsyncResult) As Integer
Return CInt(Me.EndInvoke(asyncResult))
End Function 'EndAdd
End Class 'Math
End Namespace 'MyMath
namespace MyMath {
[XmlRootAttribute("int", Namespace="http://MyMath/", IsNullable=false)]
public class Math : HttpGetClientProtocol {
public Math()
{
this.Url = "https://www.contoso.com/math.asmx";
}
[HttpMethodAttribute(typeof(System.Web.Services.Protocols.XmlReturnReader),
typeof(System.Web.Services.Protocols.UrlParameterWriter))]
public int Add(int num1, int num2)
{
return ((int)(this.Invoke("Add", ((this.Url) + ("/Add")), new object[] {num1,
num2})));
}
public IAsyncResult BeginAdd(int num1, int num2, AsyncCallback callback, object asyncState)
{
return this.BeginInvoke("Add", ((this.Url) + ("/Add")), new object[] {num1,
num2}, callback, asyncState);
}
public int EndAdd(IAsyncResult asyncResult)
{
return ((int)(this.EndInvoke(asyncResult)));
}
}
}
namespace MyMath
{
[XmlRootAttribute("snippet1>",Namespace="http://MyMath/",IsNullable=false)]
public ref class Math: public HttpGetClientProtocol
{
public:
Math()
{
this->Url = "https://www.contoso.com/math.asmx";
}
[HttpMethodAttribute(System::Web::Services::Protocols::XmlReturnReader::typeid,
System::Web::Services::Protocols::UrlParameterWriter::typeid)]
int Add( String^ num1, String^ num2 )
{
array<Object^>^temp0 = {num1,num2};
return *dynamic_cast<int^>(this->Invoke( "Add", String::Concat( this->Url, "/Add" ), temp0 ));
}
IAsyncResult^ BeginAdd( String^ num1, String^ num2, AsyncCallback^ callback, Object^ asyncState )
{
array<Object^>^temp1 = {num1,num2};
return this->BeginInvoke( "Add", String::Concat( this->Url, "/Add" ), temp1, callback, asyncState );
}
int EndAdd( IAsyncResult^ asyncResult )
{
return *dynamic_cast<int^>(this->EndInvoke( asyncResult ));
}
};
}
Im folgenden Codebeispiel wird der Math-XML-Webdienst veranschaulicht, aus dem die vorherige 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;
}
}
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
HttpSimpleClientProtocol-Klasse
HttpSimpleClientProtocol-Member
System.Web.Services.Protocols-Namespace
IAsyncResult