DataServiceContext.BeginExecute Methode

Definition

Sendet asynchron eine Anforderung an den Datendienst, um einen bestimmten URI auszuführen.

Überlädt

BeginExecute<T>(DataServiceQueryContinuation<T>, AsyncCallback, Object)

Sendet asynchron eine Anforderung an den Datendienst, um die nächste Seite der Daten in einem ausgelagerten Abfrageergebnis abzurufen.

BeginExecute<TElement>(Uri, AsyncCallback, Object)

Asynchron sendet die Anforderung, damit dieser Aufruf beim Warten auf die Ergebnisse vom Dienst keine Verarbeitung blockiert.

BeginExecute<T>(DataServiceQueryContinuation<T>, AsyncCallback, Object)

Sendet asynchron eine Anforderung an den Datendienst, um die nächste Seite der Daten in einem ausgelagerten Abfrageergebnis abzurufen.

public:
generic <typename T>
 IAsyncResult ^ BeginExecute(System::Data::Services::Client::DataServiceQueryContinuation<T> ^ continuation, AsyncCallback ^ callback, System::Object ^ state);
public IAsyncResult BeginExecute<T> (System.Data.Services.Client.DataServiceQueryContinuation<T> continuation, AsyncCallback callback, object state);
member this.BeginExecute : System.Data.Services.Client.DataServiceQueryContinuation<'T> * AsyncCallback * obj -> IAsyncResult
Public Function BeginExecute(Of T) (continuation As DataServiceQueryContinuation(Of T), callback As AsyncCallback, state As Object) As IAsyncResult

Typparameter

T

Der von der Abfrage zurückgegebene Typ.

Parameter

continuation
DataServiceQueryContinuation<T>

Ein DataServiceQueryContinuation<T>-Objekt, das die nächste Seite der Daten darstellt, die vom Datendienst zurückgegeben werden.

callback
AsyncCallback

Delegat, der aufgerufen werden soll, wenn Ergebnisse für die Verwendung durch den Client verfügbar sind.

state
Object

Benutzerdefiniertes Statusobjekt, das an den Rückruf übergeben wird.

Gibt zurück

IAsyncResult für den Status des Vorgangs.

Hinweise

Das angegebene DataServiceQueryContinuation<T>-Objekt enthält den URI der bei Ausführung die nächste Seite der Daten im Abfrageergebnis zurück.

Gilt für:

BeginExecute<TElement>(Uri, AsyncCallback, Object)

Asynchron sendet die Anforderung, damit dieser Aufruf beim Warten auf die Ergebnisse vom Dienst keine Verarbeitung blockiert.

public:
generic <typename TElement>
 IAsyncResult ^ BeginExecute(Uri ^ requestUri, AsyncCallback ^ callback, System::Object ^ state);
public IAsyncResult BeginExecute<TElement> (Uri requestUri, AsyncCallback callback, object state);
member this.BeginExecute : Uri * AsyncCallback * obj -> IAsyncResult
Public Function BeginExecute(Of TElement) (requestUri As Uri, callback As AsyncCallback, state As Object) As IAsyncResult

Typparameter

TElement

Der von der Abfrage zurückgegebene Typ.

Parameter

requestUri
Uri

Der URI, an den die generierte Abfrage gesendet wird. Der URI kann jeder gültige Datendienst-URI sein. Er kann $-Abfrageparameter enthalten.

callback
AsyncCallback

Delegat, der aufgerufen werden soll, wenn Ergebnisse für die Verwendung durch den Client verfügbar sind.

state
Object

Benutzerdefiniertes Statusobjekt, das an den Rückruf übergeben wird.

Gibt zurück

Ein Objekt, das verwendet wird, um den Status des asynchronen Vorgangs nachzuverfolgen.

Beispiele

Im folgenden Beispiel wird gezeigt, wie eine asynchrone Abfrage durch Aufrufen der BeginExecute-Methode zum Starten der Abfrage ausgeführt wird. Der Inlinedelegat ruft die EndExecute-Methode zum Anzeigen der Abfrageergebnisse auf. In diesem Beispiel wird das DataServiceContext vom Tool Dienstverweis hinzufügen basierend auf dem Northwind-Datendienst generiert, der erstellt wird, wenn Sie die WCF Data Services abschließen.

public static void BeginExecuteCustomersQuery()
{
    // Create the DataServiceContext using the service URI.
    NorthwindEntities context = new NorthwindEntities(svcUri);

    // Define the query to execute asynchronously that returns
    // all customers with their respective orders.
    DataServiceQuery<Customer> query = (DataServiceQuery<Customer>)(from cust in context.Customers.Expand("Orders")
                                       where cust.CustomerID == "ALFKI"
                                       select cust);

    try
    {
        // Begin query execution, supplying a method to handle the response
        // and the original query object to maintain state in the callback.
        query.BeginExecute(OnCustomersQueryComplete, query);
    }
    catch (DataServiceQueryException ex)
    {
        throw new ApplicationException(
            "An error occurred during query execution.", ex);
    }
}

// Handle the query callback.
private static void OnCustomersQueryComplete(IAsyncResult result)
{
    // Get the original query from the result.
    DataServiceQuery<Customer> query =
        result as DataServiceQuery<Customer>;

    foreach (Customer customer in query.EndExecute(result))
    {
        Console.WriteLine("Customer Name: {0}", customer.CompanyName);
        foreach (Order order in customer.Orders)
        {
            Console.WriteLine("Order #: {0} - Freight $: {1}",
                order.OrderID, order.Freight);
        }
    }
}
Public Shared Sub BeginExecuteCustomersQuery()
    ' Create the DataServiceContext using the service URI.
    Dim context = New NorthwindEntities(svcUri)

    ' Define the delegate to callback into the process
    Dim callback As AsyncCallback = AddressOf OnCustomersQueryComplete

    ' Define the query to execute asynchronously that returns 
    ' all customers with their respective orders.
    Dim query As DataServiceQuery(Of Customer) = _
    context.Customers.Expand("Orders")

    Try
        ' Begin query execution, supplying a method to handle the response
        ' and the original query object to maintain state in the callback.
        query.BeginExecute(callback, query)
    Catch ex As DataServiceQueryException
        Throw New ApplicationException( _
                "An error occurred during query execution.", ex)
    End Try
End Sub
' Handle the query callback.
Private Shared Sub OnCustomersQueryComplete(ByVal result As IAsyncResult)
    ' Get the original query from the result.
    Dim query As DataServiceQuery(Of Customer) = _
        CType(result.AsyncState, DataServiceQuery(Of Customer))

    ' Complete the query execution.
    For Each customer As Customer In query.EndExecute(result)
        Console.WriteLine("Customer Name: {0}", customer.CompanyName)
        For Each order As Order In customer.Orders
            Console.WriteLine("Order #: {0} - Freight $: {1}", _
                    order.OrderID, order.Freight)
        Next
    Next
End Sub

Hinweise

Das zurückgegebene IAsyncResult-Objekt wird verwendet, um den Abschluss des asynchronen Vorgangs zu ermitteln. Weitere Informationen finden Sie unter Asynchrone Vorgänge.

Der Methode BeginExecute verwendet die gleiche Semantik wie Execute. Diese Methode sendet die Anforderung jedoch asynchron, sodass dieser Aufruf beim Warten auf die Ergebnisse vom Dienst keine Verarbeitung blockiert. Entsprechend dem asynchronen Begin/End-Standardmuster wird beim Abrufen der Abfrageergebnisse der bereitgestellte Rückruf aufgerufen.

Weitere Informationen

Gilt für: