Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance.
        /// </summary>
        /// <param name="request"></param>
        /// <param name="lease"></param>
        /// <param name="encoderFactory"></param>
        /// <param name="bufferManager"></param>
        /// <param name="localAddress"></param>
        /// <param name="parent"></param>
        public AspNetCoreReplyChannel(
            AspNetCoreRequest request,
            AspNetCoreRequestQueueLease lease,
            MessageEncoderFactory encoderFactory,
            BufferManager bufferManager,
            EndpointAddress localAddress,
            AspNetCoreReplyChannelListener parent) :
            base(parent)
        {
            this.request       = request ?? throw new ArgumentNullException(nameof(request));
            this.lease         = lease ?? throw new ArgumentNullException(nameof(lease));
            this.bufferManager = bufferManager ?? throw new ArgumentNullException(nameof(bufferManager));

            this.localAddress = localAddress ?? throw new ArgumentNullException(nameof(localAddress));
            encoder           = encoderFactory.CreateSessionEncoder();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Sends the reply message by writing it back to the HTTP response.
        /// </summary>
        /// <param name="message"></param>
        /// <param name="timeout"></param>
        /// <returns></returns>
        internal async Task ReplyAsync(Message message, AspNetCoreRequest request, TimeSpan timeout)
        {
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            try
            {
                // incoming request was canceled
                if (request.Context.RequestAborted.IsCancellationRequested)
                {
                    throw new CommunicationObjectAbortedException();
                }

                ThrowIfDisposedOrNotOpen();

                await WriteMessageAsync(request.Context.Response, message).ConfigureAwait(false);

                // indicate that request is finished
                request.TrySetResult(true);
            }
            catch (CommunicationException e)
            {
                request.TrySetException(e);
                throw;
            }
            catch (Exception e)
            {
                request.TrySetException(e);
                throw new CommunicationException(e.Message, e);
            }
            finally
            {
                if (lease != null)
                {
                    lease.Dispose();
                    lease = null;
                }
            }
        }