/// <summary> /// Completes an asynchronous operation to return a, possibly converted, <see cref="XmlMessage"/>-based response to a /// relayed <see cref="XmlMessage"/>-based request. /// </summary> /// <typeparam name="TResponse"> /// The type of the <see cref="XmlMessage"/>-based response. /// </typeparam> /// <param name="asyncResult"> /// The <see cref="IAsyncResult"/> returned by a call to the <see /// cref="BeginRelayRequest{TRequest}(TRequest,AsyncCallback,object)"/> method. /// </param> /// <returns> /// The <see cref="XmlMessage"/>-based response. /// </returns> protected TResponse EndRelayRequest <TResponse>(IAsyncResult asyncResult) where TResponse : XmlMessage, new() { if (asyncResult == null) { throw new ArgumentNullException(nameof(asyncResult)); } if (_logger.IsInfoEnabled) { _logger.InfoFormat("Beginning relaying asynchronous response {0}.", typeof(TResponse).Name); } ClientRelay clientRelay = null; try { var wrappedAsyncResult = ((AsyncResultWrapper)asyncResult).WrappedAsyncResult; clientRelay = (ClientRelay)wrappedAsyncResult.AsyncState; var response = clientRelay.EndRequest <TResponse>(wrappedAsyncResult); clientRelay.Close(); if (_logger.IsInfoEnabled) { _logger.InfoFormat("Relaying asynchronous response {0} succeeded.", response); } return(response); } catch (Exception exception) { if (_logger.IsWarnEnabled) { _logger.Warn($"Relaying asynchronous response {typeof(TResponse).Name} failed.", exception); } clientRelay?.Abort(); throw; } }
private TResponse RelayRequest <TRequest, TResponse>(TRequest request, Func <ClientRelay, TimeSpan> getTimeout, IXmlMessageConverter converter) where TRequest : XmlMessage where TResponse : XmlMessage, new() { if (_logger.IsInfoEnabled) { _logger.InfoFormat("Relaying synchronous request {0}.", request); } ClientRelay clientRelay = null; try { clientRelay = _clientRelayFactory(); var response = clientRelay.Request <TRequest, TResponse>(request, getTimeout(clientRelay), converter); clientRelay.Close(); if (_logger.IsInfoEnabled) { _logger.InfoFormat("Relaying synchronous response {0} succeeded.", response); } return(response); } catch (Exception exception) { if (_logger.IsWarnEnabled) { _logger.Warn($"Relaying synchronous response {typeof(TResponse).Name} failed.", exception); } clientRelay?.Abort(); throw; } }