public async Task <TResponse> GetResponseAsync() { try { using (StartScope()) { await SendTask.ConfigureAwait(false); // Trailers are only available once the response body had been read var responseStream = await HttpResponse.Content.ReadAsStreamAsync().ConfigureAwait(false); var message = await responseStream.ReadSingleMessageAsync(Logger, Method.ResponseMarshaller.Deserializer, _callCts.Token).ConfigureAwait(false); FinishResponse(); if (message == null) { Log.MessageNotReturned(Logger); throw new InvalidOperationException("Call did not return a response message"); } // The task of this method is cached so there is no need to cache the message here return(message); } } catch (OperationCanceledException) { EnsureNotDisposed(); throw CreateCanceledStatusException(); } }
public async Task <Metadata> GetResponseHeadersAsync() { try { await SendTask.ConfigureAwait(false); // The task of this method is cached so there is no need to cache the headers here return(GrpcProtocolHelpers.BuildMetadata(HttpResponse.Headers)); } catch (OperationCanceledException) { EnsureNotDisposed(); throw CreateCanceledStatusException(); } }
public async Task <TResponse> GetResponseAsync() { Debug.Assert(SendTask != null); try { using (StartScope()) { await SendTask.ConfigureAwait(false); Debug.Assert(HttpResponse != null); // Trailers are only available once the response body had been read var responseStream = await HttpResponse.Content.ReadAsStreamAsync().ConfigureAwait(false); var message = await responseStream.ReadSingleMessageAsync( Logger, Method.ResponseMarshaller.ContextualDeserializer, GrpcProtocolHelpers.GetGrpcEncoding(HttpResponse), Channel.ReceiveMaxMessageSize, Channel.CompressionProviders, _callCts.Token).ConfigureAwait(false); FinishResponse(); if (message == null) { Log.MessageNotReturned(Logger); throw new InvalidOperationException("Call did not return a response message"); } GrpcEventSource.Log.MessageReceived(); // The task of this method is cached so there is no need to cache the message here return(message); } } catch (OperationCanceledException) { EnsureNotDisposed(); throw CreateCanceledStatusException(); } }
public async Task <Metadata> GetResponseHeadersAsync() { Debug.Assert(SendTask != null); try { using (StartScope()) { await SendTask.ConfigureAwait(false); Debug.Assert(HttpResponse != null); // The task of this method is cached so there is no need to cache the headers here return(GrpcProtocolHelpers.BuildMetadata(HttpResponse.Headers)); } } catch (OperationCanceledException) when(!Channel.ThrowOperationCanceledOnCancellation) { throw CreateCanceledStatusException(); } }
public async Task <TResponse> GetResponseAsync() { Debug.Assert(SendTask != null); try { using (StartScope()) { // Wait for send to finish so the HttpResponse is available await SendTask.ConfigureAwait(false); // Verify the call is not complete. The call should be complete once the grpc-status // has been read from trailers, which happens AFTER the message has been read. if (CallTask.IsCompletedSuccessfully) { var status = CallTask.Result; if (status.StatusCode != StatusCode.OK) { throw new RpcException(status); } else { // The server should never return StatusCode.OK in the header for a unary call. // If it does then throw an error that no message was returned from the server. Log.MessageNotReturned(Logger); throw new InvalidOperationException("Call did not return a response message"); } } Debug.Assert(HttpResponse != null); // Trailers are only available once the response body had been read var responseStream = await HttpResponse.Content.ReadAsStreamAsync().ConfigureAwait(false); var message = await responseStream.ReadSingleMessageAsync( Logger, Method.ResponseMarshaller.ContextualDeserializer, GrpcProtocolHelpers.GetGrpcEncoding(HttpResponse), Channel.ReceiveMaxMessageSize, Channel.CompressionProviders, _callCts.Token).ConfigureAwait(false); FinishResponse(throwOnFail: true); if (message == null) { Log.MessageNotReturned(Logger); throw new InvalidOperationException("Call did not return a response message"); } GrpcEventSource.Log.MessageReceived(); // The task of this method is cached so there is no need to cache the message here return(message); } } catch (OperationCanceledException) when(!Channel.ThrowOperationCanceledOnCancellation) { throw CreateCanceledStatusException(); } }