DataServiceContext.EndExecute<TElement>(IAsyncResult) 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
를 완료하기 위해 호출되었습니다 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 개체
반품
쿼리 작업에서 반환된 결과입니다.
예외
시기 asyncResult 입니다.null
이 DataServiceContext 인스턴스에서 시작되지 않은 경우 asyncResult 입니다.
-또는-
이 메서드는 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 호출되면 a가 DataServiceResponse 만들어지고 반환되지만 결과가 아직 처리되지 않았습니다. ID 확인, 개체 구체화 및 조작은 사용자가 결과를 열거할 때만 발생합니다.