DataServiceContext.Execute<TElement> メソッド (Uri)

要求をデータ サービスに送信して特定の 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 は、絶対 URI にも相対 URI にもすることができます。

requestUri が絶対 URI の場合、このメソッドは、その URI が DataServiceContext の作成時に指定されたのと同じデータ サービスを指すかどうかを検証します。 requestUri が相対 URI である場合、このメソッドは、先頭のスラッシュを削除し、DataServiceContext の作成時に指定された文字列に requestUri を追加します。 スラッシュは、DataServiceContext コンストラクターに渡された URI の後に追加されます (スラッシュがない場合)。

このメソッドから制御が戻った時点で、要求に対するすべての HTTP 応答がネットワーク ストリームから読み取られていますが、応答は処理されていません。また、ID 解決やオブジェクトの具体化も行われません。 列挙されるまで、応答内の特定のエンティティに対する 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);
}

関連項目

参照

DataServiceContext クラス

Execute オーバーロード

System.Data.Services.Client 名前空間

その他の技術情報

遅延コンテンツの読み込み (WCF Data Services)

方法: ページングされた結果を読み込む (WCF Data Services)