public async Task HandleCallAsync(HttpContext httpContext)
        {
            var requestMessage = await CreateMessage(httpContext);

            var serverCallContext = new HttpApiServerCallContext();

            var response = await _unaryMethodInvoker.Invoke(httpContext, serverCallContext, (TRequest)requestMessage);

            await SendResponse(httpContext, response);
        }
Пример #2
0
        public async Task HandleCallAsync(HttpContext httpContext)
        {
            var requestMessage = await CreateMessage(httpContext.Request);

            var serverCallContext = new HttpApiServerCallContext();

            var responseMessage = await _unaryMethodInvoker.Invoke(httpContext, serverCallContext, (TRequest)requestMessage);

            var selectedEncoding = ResponseEncoding.SelectCharacterEncoding(httpContext.Request);

            await SendResponse(httpContext.Response, selectedEncoding, responseMessage);
        }
Пример #3
0
        public async Task HandleCallAsync(HttpContext httpContext)
        {
            var selectedEncoding = ResponseEncoding.SelectCharacterEncoding(httpContext.Request);

            var(requestMessage, requestStatusCode, errorMessage) = await CreateMessage(httpContext.Request);

            if (requestMessage == null || requestStatusCode != StatusCode.OK)
            {
                await SendErrorResponse(httpContext.Response, selectedEncoding, errorMessage ?? string.Empty, requestStatusCode);

                return;
            }

            var serverCallContext = new HttpApiServerCallContext(httpContext, _unaryMethodInvoker.Method.FullName);

            TResponse responseMessage;

            try
            {
                responseMessage = await _unaryMethodInvoker.Invoke(httpContext, serverCallContext, (TRequest)requestMessage);
            }
            catch (Exception ex)
            {
                StatusCode statusCode;
                string     message;

                if (ex is RpcException rpcException)
                {
                    message    = rpcException.Message;
                    statusCode = rpcException.StatusCode;
                }
                else
                {
                    // TODO - Add option for detailed error messages
                    message    = "Exception was thrown by handler.";
                    statusCode = StatusCode.Unknown;
                }

                await SendErrorResponse(httpContext.Response, selectedEncoding, message, statusCode);

                return;
            }

            if (serverCallContext.Status.StatusCode != StatusCode.OK)
            {
                await SendErrorResponse(httpContext.Response, selectedEncoding, serverCallContext.Status.ToString(), serverCallContext.Status.StatusCode);

                return;
            }

            await SendResponse(httpContext.Response, selectedEncoding, responseMessage);
        }