Share via


Container.ReadItemStreamAsync Método

Definición

Lee un elemento del servicio Azure Cosmos como una operación asincrónica.

public abstract System.Threading.Tasks.Task<Microsoft.Azure.Cosmos.ResponseMessage> ReadItemStreamAsync (string id, Microsoft.Azure.Cosmos.PartitionKey partitionKey, Microsoft.Azure.Cosmos.ItemRequestOptions requestOptions = default, System.Threading.CancellationToken cancellationToken = default);
abstract member ReadItemStreamAsync : string * Microsoft.Azure.Cosmos.PartitionKey * Microsoft.Azure.Cosmos.ItemRequestOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Azure.Cosmos.ResponseMessage>
Public MustOverride Function ReadItemStreamAsync (id As String, partitionKey As PartitionKey, Optional requestOptions As ItemRequestOptions = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Task(Of ResponseMessage)

Parámetros

id
String

El identificador del elemento de Cosmos

partitionKey
PartitionKey

Clave de partición del elemento.

requestOptions
ItemRequestOptions

(Opcional) Las opciones de la solicitud de elemento.

cancellationToken
CancellationToken

(Opcional) CancellationToken que representa la cancelación de la solicitud.

Devoluciones

que Task contiene un ResponseMessage objeto que contiene Stream el registro de recursos de lectura.

Ejemplos

Lee una respuesta como una secuencia.

using(ResponseMessage response = await this.container.ReadItemStreamAsync("id", new PartitionKey("partitionKey")))
{
    if (!response.IsSuccessStatusCode)
    {
        //Handle and log exception
        return;
    }

    //Read or do other operations with the stream
    using (StreamReader streamReader = new StreamReader(response.Content))
    {
        string content = await streamReader.ReadToEndAsync();
    }
}

Comentarios

La operación Stream solo se inicia en excepciones del lado cliente. Esto es para aumentar el rendimiento y evitar la sobrecarga de iniciar excepciones. Compruebe el código de estado HTTP en la respuesta para comprobar si se produjo un error en la operación.

Se aplica a