public async Task RegisterObserverActorAsync(GatewayRequest request)
        {
            try
            {
                // Validates parameter
                if (string.IsNullOrWhiteSpace(request?.Topic) ||
                    (request.ObserverEntityId?.ServiceUri == null) ||
                    (request.ObserverEntityId.ActorId == null) ||
                    (request.ObservableEntityId == null))
                {
                    throw new ArgumentException($"Parameter {nameof(request)} is null or invalid.", nameof(request));
                }

                // Gets actor proxy
                IClientObserverActor proxy = GetActorProxy(
                    new ActorId(request.ObserverEntityId.ActorId),
                    request.ObserverEntityId.ServiceUri);
                if (proxy == null)
                {
                    throw new ApplicationException("The ActorProxy cannot be null.");
                }

                // Invokes actor using proxy
                ServiceEventSource.Current.Message(
                    $"Registering observer...\r\n[Observable]: {request.ObservableEntityId}\r\n[Observer]: {request.ObserverEntityId}\r\n[Publication]: Topic=[{request.Topic}]");
                await proxy.RegisterObserverActorAsync(request.Topic, request.FilterExpressions, new EntityId(request.ObservableEntityId));
            }
            catch (AggregateException ex)
            {
                if (!(ex.InnerExceptions?.Count > 0))
                {
                    return;
                }
                foreach (Exception exception in ex.InnerExceptions)
                {
                    ServiceEventSource.Current.Message(exception.Message);
                }
                throw new HttpResponseException(this.Request.CreateErrorResponse(HttpStatusCode.NotFound, ex.Message));
            }
            catch (Exception ex)
            {
                ServiceEventSource.Current.Message(ex.Message);
                throw new HttpResponseException(this.Request.CreateErrorResponse(HttpStatusCode.NotFound, ex.Message));
            }
        }
        public async Task <IEnumerable <Message> > ReadMessagesFromMessageBoxAsync(GatewayRequest request)
        {
            try
            {
                // Validates parameter
                if ((request.ObserverEntityId?.ServiceUri == null) ||
                    (request.ObserverEntityId.ActorId == null))
                {
                    throw new ArgumentException($"Parameter {nameof(request)} is null or invalid.", nameof(request));
                }

                // Gets actor proxy
                IClientObserverActor proxy = GetActorProxy(
                    new ActorId(request.ObserverEntityId.ActorId),
                    request.ObserverEntityId.ServiceUri);
                if (proxy == null)
                {
                    throw new ApplicationException("The ActorProxy cannot be null.");
                }

                // Invokes actor using proxy
                ServiceEventSource.Current.Message($"Reading messages from the MessageBox...\r\n[Observer]: {request.ObserverEntityId}");
                return(await proxy.ReadMessagesFromMessageBoxAsync());
            }
            catch (AggregateException ex)
            {
                if (!(ex.InnerExceptions?.Count > 0))
                {
                    throw new HttpResponseException(this.Request.CreateErrorResponse(HttpStatusCode.NotFound, ex.Message));
                }
                foreach (Exception exception in ex.InnerExceptions)
                {
                    ServiceEventSource.Current.Message(exception.Message);
                }
                throw new HttpResponseException(this.Request.CreateErrorResponse(HttpStatusCode.NotFound, ex.Message));
            }
            catch (Exception ex)
            {
                ServiceEventSource.Current.Message(ex.Message);
                throw new HttpResponseException(this.Request.CreateErrorResponse(HttpStatusCode.NotFound, ex.Message));
            }
        }
        public async Task ClearSubscriptionsAsync(GatewayRequest request)
        {
            try
            {
                // Validates parameter
                if (request.ObserverEntityId?.ServiceUri == null ||
                    request.ObserverEntityId.ActorId == null)
                {
                    throw new ArgumentException($"Parameter {nameof(request)} is null or invalid.", nameof(request));
                }

                // Gets actor proxy
                IClientObserverActor proxy = GetActorProxy(new ActorId(request.ObserverEntityId.ActorId),
                                                           request.ObserverEntityId.ServiceUri);
                if (proxy == null)
                {
                    throw new ApplicationException("The ActorProxy cannot be null.");
                }

                // Invokes actor using proxy
                ServiceEventSource.Current.Message($"Clearing observer subscriptions...\r\n[Observer]: {request.ObserverEntityId}");
                await proxy.ClearSubscriptionsAsync();
            }
            catch (AggregateException ex)
            {
                if (!(ex.InnerExceptions?.Count > 0))
                {
                    throw;
                }
                foreach (Exception exception in ex.InnerExceptions)
                {
                    ServiceEventSource.Current.Message(exception.Message);
                }
                throw;
            }
            catch (Exception ex)
            {
                ServiceEventSource.Current.Message(ex.Message);
                throw;
            }
        }