protected override async Task HandleCallAsyncCore(HttpContext httpContext, HttpContextServerCallContext serverCallContext)
        {
            // Disable request body data rate for client streaming
            DisableMinRequestBodyDataRateAndMaxRequestBodySize(httpContext);

            TResponse?response;

            var streamReader = new HttpContextStreamReader <TRequest>(serverCallContext, MethodInvoker.Method.RequestMarshaller.ContextualDeserializer);

            try
            {
                response = await _invoker.Invoke(httpContext, serverCallContext, streamReader);
            }
            finally
            {
                streamReader.Complete();
            }

            if (response == null)
            {
                // This is consistent with Grpc.Core when a null value is returned
                throw new RpcException(new Status(StatusCode.Cancelled, "No message returned from method."));
            }

            // Check if deadline exceeded while method was invoked. If it has then skip trying to write
            // the response message because it will always fail.
            // Note that the call is still going so the deadline could still be exceeded after this point.
            if (serverCallContext.DeadlineManager?.IsDeadlineExceededStarted ?? false)
            {
                return;
            }

            var responseBodyWriter = httpContext.Response.BodyWriter;
            await responseBodyWriter.WriteSingleMessageAsync(response, serverCallContext, MethodInvoker.Method.ResponseMarshaller.ContextualSerializer);
        }
Esempio n. 2
0
        protected override async Task HandleCallAsyncCore(HttpContext httpContext, HttpContextServerCallContext serverCallContext)
        {
            // Disable request body data rate for client streaming
            DisableMinRequestBodyDataRateAndMaxRequestBodySize(httpContext);

            var streamReader = new HttpContextStreamReader <TRequest>(serverCallContext, MethodInvoker.Method.RequestMarshaller.ContextualDeserializer);
            var response     = await _invoker.Invoke(httpContext, serverCallContext, streamReader);

            if (response == null)
            {
                // This is consistent with Grpc.Core when a null value is returned
                throw new RpcException(new Status(StatusCode.Cancelled, "No message returned from method."));
            }

            if (serverCallContext.DeadlineManager != null && serverCallContext.DeadlineManager.CancellationToken.IsCancellationRequested)
            {
                // The cancellation token has been raised. Ensure that any DeadlineManager tasks have
                // been completed before continuing.
                await serverCallContext.DeadlineManager.CancellationProcessedTask;

                // There is no point trying to write to the response because it has been finished.
                if (serverCallContext.DeadlineManager.CallComplete)
                {
                    return;
                }
            }

            var responseBodyWriter = httpContext.Response.BodyWriter;
            await responseBodyWriter.WriteMessageAsync(response, serverCallContext, MethodInvoker.Method.ResponseMarshaller.ContextualSerializer, canFlush : false);
        }
Esempio n. 3
0
        protected override async Task HandleCallAsyncCore(HttpContext httpContext, HttpContextServerCallContext serverCallContext)
        {
            // Disable request body data rate for client streaming
            DisableMinRequestBodyDataRateAndMaxRequestBodySize(httpContext);

            var streamReader = new HttpContextStreamReader <TRequest>(serverCallContext, MethodInvoker.Method.RequestMarshaller.ContextualDeserializer);
            var response     = await _invoker.Invoke(httpContext, serverCallContext, streamReader);

            if (response == null)
            {
                // This is consistent with Grpc.Core when a null value is returned
                throw new RpcException(new Status(StatusCode.Cancelled, "No message returned from method."));
            }

            var responseBodyWriter = httpContext.Response.BodyWriter;
            await responseBodyWriter.WriteMessageAsync(response, serverCallContext, MethodInvoker.Method.ResponseMarshaller.ContextualSerializer, canFlush : false);
        }