Share via


Container.ReadItemStreamAsync Método

Definição

Lê um item do serviço do Azure Cosmos como uma operação assíncrona.

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

A ID do item do Cosmos

partitionKey
PartitionKey

A chave de partição do item.

requestOptions
ItemRequestOptions

(Opcional) As opções para a solicitação de item.

cancellationToken
CancellationToken

(Opcional) CancellationToken que representa o cancelamento da solicitação.

Retornos

Um Task que contém um ResponseMessage que encapsula um Stream que contém o registro de recurso de leitura.

Exemplos

Leia uma resposta como um fluxo.

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

Comentários

A operação Stream só gera exceções do lado do cliente. Isso é para aumentar o desempenho e evitar a sobrecarga de gerar exceções. Verifique o código http status na resposta ao marcar se a operação falhou.

Aplica-se a