Share via


DataServiceContext.EndExecute<TElement>(IAsyncResult) 메서드

정의

BeginExecute<TElement>(Uri, AsyncCallback, Object)을 완료하기 위해 호출됩니다.

public:
generic <typename TElement>
 System::Collections::Generic::IEnumerable<TElement> ^ EndExecute(IAsyncResult ^ asyncResult);
public System.Collections.Generic.IEnumerable<TElement> EndExecute<TElement> (IAsyncResult asyncResult);
member this.EndExecute : IAsyncResult -> seq<'Element>
Public Function EndExecute(Of TElement) (asyncResult As IAsyncResult) As IEnumerable(Of TElement)

형식 매개 변수

TElement

쿼리에서 반환되는 형식입니다.

매개 변수

asyncResult
IAsyncResult

IAsyncResult 개체입니다.

반환

IEnumerable<TElement>

쿼리 작업에서 반환하는 결과입니다.

예외

asyncResultnull일 경우

asyncResult가 이 DataServiceContext 인스턴스에서 시작되지 않은 경우

또는

EndExecute<TElement>(IAsyncResult) 메서드가 이미 호출된 경우

요청을 실행하는 동안 오류가 발생하거나 응답 메시지의 내용을 개체로 변환하는 경우.

예제

다음 예제에서는 메서드를 호출하여 비동기 쿼리를 BeginExecute 실행하여 쿼리를 시작하는 방법을 보여줍니다. 인라인 대리자는 메서드를 EndExecute 호출하여 쿼리 결과를 표시합니다. 이 예제에서는 WCF Data Services 완료할 때 만들어지는 Northwind 데이터 서비스를 기반으로 서비스 참조 추가 도구에서 생성된 를 사용합니다DataServiceContext.

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

설명

제공된 콜백은 표준 시작-끝 비동기 패턴에 따라 쿼리 결과가 검색되면 호출됩니다. 자세한 내용은 비동기 작업합니다.

콜백이 호출되면 HTTP 스트림에서 모든 결과를 읽었지만 처리되지 않았습니다. 로컬 사용자 지향 개체가 구체화되거나 수정되지 않았으며 ID 확인이 발생하지 않았습니다. EndExecute 가 호출되면 가 DataServiceResponse 만들어지고 반환되지만 결과가 아직 처리되지 않았습니다. ID 확인, 개체 구체화 및 조작은 사용자가 결과를 열거할 때만 발생합니다.

적용 대상

추가 정보