다음을 통해 공유


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

BeginExecute를 완료하기 위해 호출됩니다.

네임스페이스:  System.Data.Services.Client
어셈블리:  Microsoft.Data.Services.Client(Microsoft.Data.Services.Client.dll)

구문

‘선언
Public Function EndExecute(Of TElement) ( _
    asyncResult As IAsyncResult _
) As IEnumerable(Of TElement)
‘사용 방법
Dim instance As DataServiceContext
Dim asyncResult As IAsyncResult
Dim returnValue As IEnumerable(Of TElement)

returnValue = instance.EndExecute(asyncResult)
public IEnumerable<TElement> EndExecute<TElement>(
    IAsyncResult asyncResult
)
public:
generic<typename TElement>
IEnumerable<TElement>^ EndExecute(
    IAsyncResult^ asyncResult
)
member EndExecute : 
        asyncResult:IAsyncResult -> IEnumerable<'TElement> 
JScript는 제네릭 형식 및 메서드를 지원하지 않습니다.

유형 매개 변수

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

매개 변수

반환 값

유형: System.Collections.Generic.IEnumerable<TElement>
쿼리 작업에서 반환되는 결과입니다.

예외

예외 조건
ArgumentNullException

asyncResult가 nullnull 참조(Visual Basic에서는 Nothing)인 경우

ArgumentException

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

또는

EndExecute 메서드가 이전에 호출된 경우

InvalidOperationException

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

DataServiceQueryException

데이터 서비스에서 HTTP 404: 리소스를 찾을 수 없음 오류가 반환되는 경우

주의

제공된 콜백은 표준 시작-끝 비동기 패턴에 따라 쿼리 결과가 검색되면 호출됩니다. 자세한 내용은 비동기 작업(WCF Data Services)을 참조하십시오.

콜백이 호출되면 모든 결과를 HTTP 스트림에서 읽었지만 결과가 처리되지 않은 것입니다. 즉, 로컬 사용자 쪽 개체가 구체화되거나 수정되지 않았고 ID 확인이 수행되지 않았습니다. EndExecute가 호출되면 DataServiceResponse가 만들어져 반환되었지만 결과가 아직 처리되지 않은 것입니다. 사용자가 결과를 열거하는 경우에만 ID 확인, 개체 구체화 및 조작이 수행됩니다.

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

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
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);
        }
    }
}    

참고 항목

참조

DataServiceContext 클래스

EndExecute 오버로드

System.Data.Services.Client 네임스페이스

관련 자료

방법: 비동기 데이터 서비스 쿼리 실행(WCF Data Service)