Example #1
0
        private void ServiceAsyncRequestResponseMethod(
            Type requestType, Type responseType,
            MethodInfo concreteMethodInfo,
            RequestResponseOperationAttribute requestResponseAttribute)
        {
            var thisType         = GetType();
            var openMethodInfo   = GetGenericMethod(thisType, "ServiceAsyncRequestResponseMethodGeneric");
            var typeArguments    = new[] { requestType, responseType };
            var closedMethodInfo = openMethodInfo.MakeGenericMethod(typeArguments);
            var parameters       = new object[] { concreteMethodInfo, requestResponseAttribute };

            closedMethodInfo.Invoke(this, parameters);
        }
Example #2
0
        // ReSharper disable UnusedMember.Local
        internal void ServiceAsyncRequestResponseMethodGeneric <TRequest, TResponse>(
            MethodInfo concreteMethodInfo,
            RequestResponseOperationAttribute requestResponseAttribute)
        // ReSharper restore UnusedMember.Local
        {
            var requestEndpointDetails = _endpointDetailsProvider
                                         .GetEndpointDetails(requestResponseAttribute.RequestEndpointKey);
            var responseEndpointDetails = _endpointDetailsProvider
                                          .GetEndpointDetails(requestResponseAttribute.ResponseEndpointKey);
            var execute =
                (Func <TRequest, IObservable <TResponse> >)Delegate.CreateDelegate(
                    typeof(Func <TRequest, IObservable <TResponse> >),
                    this, concreteMethodInfo, true);

            var subscription = _requestResponder
                               .GetRespondableRequestStream <TRequest, TResponse>(
                requestEndpointDetails,
                responseEndpointDetails)
                               .Subscribe(respondableRequest =>
            {
                RequestContext.Current =
                    new RequestContext(respondableRequest.SenderSessionId);

                try
                {
                    var response = execute(respondableRequest.Request);
                    response.Take(1).Subscribe(
                        respondableRequest.Respond,
                        respondableRequest.Respond);
                }
                catch (Exception error)
                {
                    respondableRequest.Respond(error);
                }
                finally
                {
                    RequestContext.Current = null;
                }
            });

            _subscriptions.Add(subscription);
        }