데이터 서비스에 특정 URI를 실행하라는 요청을 보냅니다.
Silverlight용 WCF Data Services 5.0 클라이언트에서 지원되지 않습니다.
네임스페이스: System.Data.Services.Client
어셈블리: Microsoft.Data.Services.Client(Microsoft.Data.Services.Client.dll)
구문
‘선언
Public Function Execute(Of TElement) ( _
requestUri As Uri _
) As IEnumerable(Of TElement)
‘사용 방법
Dim instance As DataServiceContext
Dim requestUri As Uri
Dim returnValue As IEnumerable(Of TElement)
returnValue = instance.Execute(requestUri)
public IEnumerable<TElement> Execute<TElement>(
Uri requestUri
)
public:
generic<typename TElement>
IEnumerable<TElement>^ Execute(
Uri^ requestUri
)
member Execute :
requestUri:Uri -> IEnumerable<'TElement>
JScript는 제네릭 형식 및 메서드를 지원하지 않습니다.
유형 매개 변수
- TElement
쿼리에서 반환하는 형식입니다.
매개 변수
- requestUri
유형: System.Uri
쿼리 요청을 보낼 URI입니다.URI는 유효한 모든 데이터 서비스 URI가 될 수 있습니다.$ 쿼리 매개 변수를 포함할 수 있습니다.
반환 값
유형: System.Collections.Generic.IEnumerable<TElement>
쿼리 작업의 결과입니다.
예외
| 예외 | 조건 |
|---|---|
| WebException | requestUri 요청에 대한 응답을 받지 못한 경우 |
| ArgumentNullException | requestUri가 nullnull 참조(Visual Basic에서는 Nothing)인 경우 |
| ArgumentException | requestUri가 데이터 서비스에 대한 유효한 URI가 아닌 경우 |
| InvalidOperationException | 요청을 실행하는 동안 오류가 발생하거나 응답 메시지의 내용을 개체로 변환하는 경우 |
| DataServiceQueryException | 데이터 서비스에서 HTTP 404: 리소스를 찾을 수 없음 오류가 반환되는 경우 |
주의
Execute 메서드는 URI로 데이터 서비스를 쿼리하는 데 사용됩니다. 이 메서드를 호출하면 데이터 서비스에 대한 HTTP GET 요청이 실행됩니다. 절대 또는 상대 요청 URI를 지정할 수 있습니다.
requestUri가 절대 URI인 경우 이 메서드에서는 URI가 DataServiceContext를 생성할 때 지정한 것과 동일한 데이터 서비스를 가리키는지 확인합니다. requestUri가 상대 URI인 경우 이 메서드에서는 선행 슬래시를 제거하고 DataServiceContext를 생성할 때 제공한 URI에 requestUri를 추가합니다. DataServiceContext 생성자에 전달된 URI 뒤에 슬래시(없는 경우)가 추가됩니다.
이 메서드가 반환되면 요청에 대한 전체 HTTP 응답을 네트워크 스트림에서 읽었지만 응답이 처리되지 않은 것입니다. 응답의 지정된 엔터티가 열거될 때까지 이 엔터티에 대해 ID 확인 및 전체 개체 구체화가 수행되지 않습니다.
예
이 예제에서는 do?while 루프를 사용하여 데이터 서비스의 페이징 결과에서 Customers 엔터티를 로드합니다. Execute 메서드는 데이터의 다음 페이지를 받기 위해 다음 연결 URI를 사용하여 호출됩니다.
' Create the DataServiceContext using the service URI.
Dim context = New NorthwindEntities(svcUri)
Dim token As DataServiceQueryContinuation(Of Customer) = Nothing
Dim pageCount = 0
Try
' Execute the query for all customers and get the response object.
Dim response As QueryOperationResponse(Of Customer) = _
CType(context.Customers.Execute(), QueryOperationResponse(Of Customer))
' With a paged response from the service, use a do...while loop
' to enumerate the results before getting the next link.
Do
' Write the page number.
Console.WriteLine("Page {0}:", pageCount + 1)
' If nextLink is not null, then there is a new page to load.
If token IsNot Nothing Then
' Load the new page from the next link URI.
response = CType(context.Execute(Of Customer)(token), _
QueryOperationResponse(Of Customer))
End If
' Enumerate the customers in the response.
For Each customer As Customer In response
Console.WriteLine(vbTab & "Customer Name: {0}", customer.CompanyName)
Next
' Get the next link, and continue while there is a next link.
token = response.GetContinuation()
Loop While token IsNot Nothing
Catch ex As DataServiceQueryException
Throw New ApplicationException( _
"An error occurred during query execution.", ex)
End Try
// Create the DataServiceContext using the service URI.
NorthwindEntities context = new NorthwindEntities(svcUri);
DataServiceQueryContinuation<Customer> token = null;
int pageCount = 0;
try
{
// Execute the query for all customers and get the response object.
QueryOperationResponse<Customer> response =
context.Customers.Execute() as QueryOperationResponse<Customer>;
// With a paged response from the service, use a do...while loop
// to enumerate the results before getting the next link.
do
{
// Write the page number.
Console.WriteLine("Page {0}:", pageCount++);
// If nextLink is not null, then there is a new page to load.
if (token != null)
{
// Load the new page from the next link URI.
response = context.Execute<Customer>(token)
as QueryOperationResponse<Customer>;
}
// Enumerate the customers in the response.
foreach (Customer customer in response)
{
Console.WriteLine("\tCustomer Name: {0}", customer.CompanyName);
}
}
// Get the next link, and continue while there is a next link.
while ((token = response.GetContinuation()) != null);
}
catch (DataServiceQueryException ex)
{
throw new ApplicationException(
"An error occurred during query execution.", ex);
}
참고 항목
참조
System.Data.Services.Client 네임스페이스