/// <summary>
        /// Begins an asynchronous operation to convert and transmit an <see cref="XmlMessage"/>-based request to the
        /// reply side of a request-reply message exchange within a specified interval of time.
        /// </summary>
        /// <typeparam name="TRequest">
        /// The type of the <see cref="XmlMessage"/>-based request.
        /// </typeparam>
        /// <param name="xmlRequest">
        /// The <see cref="XmlMessage"/>-based request.
        /// </param>
        /// <param name="timeout">
        /// The <see cref="TimeSpan"/> that specifies the interval of time within which a response must be received.
        /// </param>
        /// <param name="converter">
        /// The <see cref="IXmlMessageConverter"/> to use to convert the request and response.
        /// </param>
        /// <param name="asyncCallback">
        /// The <see cref="AsyncCallback"/> delegate that receives the notification of the completion of the asynchronous
        /// operation transmitting a request message.
        /// </param>
        /// <param name="asyncState">
        /// An object, specified by the application, that contains state information associated with the asynchronous
        /// operation transmitting a request message.
        /// </param>
        /// <returns>
        /// The <see cref="IAsyncResult"/> that references the asynchronous message transmission.
        /// </returns>
        /// <remarks>
        /// <para>
        /// If a timeout is passed while calling the function then that value is used. If the <see
        /// cref="Binding.SendTimeout"/> is set on the binding, then the value on the binding is used if no timeout is
        /// specified while calling the function.
        /// </para>
        /// <para>
        /// The <see cref="ChannelBase.DefaultSendTimeout"/> is used if no timeout is specified on either the binding or
        /// while calling the function. This default value is 1 minute.
        /// </para>
        /// </remarks>
        /// <seealso cref="IRequestChannel.BeginRequest(Message,TimeSpan,AsyncCallback,object)"/>
        public IAsyncResult BeginRequest <TRequest>(
            TRequest xmlRequest, TimeSpan timeout, IXmlMessageConverter converter, AsyncCallback asyncCallback, object asyncState)
            where TRequest : XmlMessage
        {
            var request = converter.CreateMessageRequestFromXmlRequest(xmlRequest);

            return(Channel.BeginRequest(
                       request,
                       timeout,
                       asyncResult => asyncCallback(new AsyncResultWrapper(asyncResult, asyncState)),
                       new object[] { request, converter }));
        }
Beispiel #2
0
        private IAsyncResult BeginRelayRequest <TRequest>(
            TRequest request,
            Func <ClientRelay, TimeSpan> getTimeout,
            IXmlMessageConverter converter,
            AsyncCallback asyncCallback,
            object asyncState)
            where TRequest : XmlMessage
        {
            if (_logger.IsInfoEnabled)
            {
                _logger.InfoFormat("Beginning relaying asynchronous request {0}.", request);
            }
            ClientRelay clientRelay = null;

            try
            {
                clientRelay = _clientRelayFactory();
                var ar = clientRelay.BeginRequest(
                    request,
                    getTimeout(clientRelay),
                    converter,
                    asyncResult => asyncCallback(new AsyncResultWrapper(asyncResult, asyncState)),
                    clientRelay);
                if (_logger.IsInfoEnabled)
                {
                    _logger.InfoFormat("Relaying asynchronous request {0} succeeded.", typeof(TRequest).Name);
                }
                return(ar);
            }
            catch (Exception exception)
            {
                if (_logger.IsWarnEnabled)
                {
                    _logger.Warn($"Relaying asynchronous request {typeof(TRequest).Name} failed.", exception);
                }
                clientRelay?.Abort();
                throw;
            }
        }
Beispiel #3
0
 /// <summary>
 /// Begins an asynchronous operation to convert and relay an <see cref="XmlMessage"/>-based request to the reply
 /// side of a request-reply message exchange within a specified interval of time.
 /// </summary>
 /// <typeparam name="TRequest">
 /// The type of the <see cref="XmlMessage"/>-based request.
 /// </typeparam>
 /// <param name="request">
 /// The <see cref="XmlMessage"/>-based request to convert and relay.
 /// </param>
 /// <param name="timeout">
 /// The <see cref="TimeSpan"/> that specifies the interval of time within which a response must be received.
 /// </param>
 /// <param name="converter">
 /// The <see cref="IXmlMessageConverter"/> to use to convert the request and response.
 /// </param>
 /// <param name="asyncCallback">
 /// The <see cref="AsyncCallback"/> delegate that receives the notification of the completion of the asynchronous
 /// operation transmitting a request message.
 /// </param>
 /// <param name="asyncState">
 /// An object, specified by the application, that contains state information associated with the asynchronous
 /// operation transmitting a request message.
 /// </param>
 /// <returns>
 /// The <see cref="IAsyncResult"/> that references the asynchronous message transmission.
 /// </returns>
 /// <remarks>
 /// <para>
 /// If a timeout is passed while calling the function then that value is used. If the <see
 /// cref="Binding.SendTimeout"/> is set on the binding, then the value on the binding is used if no timeout is
 /// specified while calling the function.
 /// </para>
 /// <para>
 /// The <see cref="ChannelBase.DefaultSendTimeout"/> is used if no timeout is specified on either the binding or
 /// while calling the function. This default value is 1 minute.
 /// </para>
 /// </remarks>
 /// <see cref="ClientRelay.BeginRequest{TRequest}(TRequest,TimeSpan,AsyncCallback,object)"/>
 protected IAsyncResult BeginRelayRequest <TRequest>(TRequest request, TimeSpan timeout, IXmlMessageConverter converter, AsyncCallback asyncCallback, object asyncState)
     where TRequest : XmlMessage
 {
     return(BeginRelayRequest(request, relay => timeout, converter, asyncCallback, asyncState));
 }
Beispiel #4
0
 /// <summary>
 /// Begins an asynchronous operation to convert and relay an <see cref="XmlMessage"/>-based request to the reply
 /// side of a request-reply message exchange.
 /// </summary>
 /// <typeparam name="TRequest">
 /// The type of the <see cref="XmlMessage"/>-based request.
 /// </typeparam>
 /// <param name="request">
 /// The <see cref="XmlMessage"/>-based request to convert and relay.
 /// </param>
 /// <param name="converter">
 /// The <see cref="IXmlMessageConverter"/> to use to convert the request and response.
 /// </param>
 /// <param name="asyncCallback">
 /// The <see cref="AsyncCallback"/> delegate that receives the notification of the completion of the asynchronous
 /// operation transmitting a request message.
 /// </param>
 /// <param name="asyncState">
 /// An object, specified by the application, that contains state information associated with the asynchronous
 /// operation transmitting a request message.
 /// </param>
 /// <returns>
 /// The <see cref="IAsyncResult"/> that references the asynchronous message transmission.
 /// </returns>
 protected IAsyncResult BeginRelayRequest <TRequest>(TRequest request, IXmlMessageConverter converter, AsyncCallback asyncCallback, object asyncState)
     where TRequest : XmlMessage
 {
     return(BeginRelayRequest(request, relay => relay.Endpoint.Binding.SendTimeout, converter, asyncCallback, asyncState));
 }
Beispiel #5
0
        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.ToString());
            }
            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.ToString());
                }
                return(response);
            }
            catch (Exception exception)
            {
                if (_logger.IsWarnEnabled)
                {
                    _logger.Warn(string.Format("Relaying synchronous response {0} failed.", typeof(TResponse).Name), exception);
                }
                if (clientRelay != null)
                {
                    clientRelay.Abort();
                }
                throw;
            }
        }
Beispiel #6
0
 /// <summary>
 /// Converts and relays an <see cref="XmlMessage"/>-based request and, converts and returns the correlated
 /// <see cref="XmlMessage"/>-based response within a specified interval of time.
 /// </summary>
 /// <typeparam name="TRequest">
 /// The type of the <see cref="XmlMessage"/>-based request.
 /// </typeparam>
 /// <typeparam name="TResponse">
 /// The type of the <see cref="XmlMessage"/>-based response.
 /// </typeparam>
 /// <param name="request">
 /// The <see cref="XmlMessage"/>-based request to convert and relay.
 /// </param>
 /// <param name="timeout">
 /// The <see cref="TimeSpan"/> that specifies the interval of time within which a response must be received.
 /// </param>
 /// <param name="converter">
 /// The <see cref="IXmlMessageConverter"/> to use to convert the request and response.
 /// </param>
 /// <returns>
 /// The converted <see cref="XmlMessage"/>-based response.
 /// </returns>
 /// <remarks>
 /// <para>
 /// If a timeout is passed while calling the function then that value is used. If the <see
 /// cref="Binding.SendTimeout"/> is set on the binding, then the value on the binding is used if no timeout is
 /// specified while calling the function.
 /// </para>
 /// <para>
 /// The <see cref="ChannelBase.DefaultSendTimeout"/> is used if no timeout is specified on either the binding or
 /// while calling the function. This default value is 1 minute.
 /// </para>
 /// </remarks>
 /// <see cref="ClientRelay.Request{TRequest,TResponse}(TRequest,TimeSpan)"/>
 protected TResponse RelayRequest <TRequest, TResponse>(TRequest request, TimeSpan timeout, IXmlMessageConverter converter)
     where TRequest : XmlMessage
     where TResponse : XmlMessage, new()
 {
     return(RelayRequest <TRequest, TResponse>(request, relay => timeout, converter));
 }
Beispiel #7
0
 /// <summary>
 /// Converts and relays an <see cref="XmlMessage"/>-based request and, converts and returns the correlated
 /// <see cref="XmlMessage"/>-based response.
 /// </summary>
 /// <typeparam name="TRequest">
 /// The type of the <see cref="XmlMessage"/>-based request.
 /// </typeparam>
 /// <typeparam name="TResponse">
 /// The type of the <see cref="XmlMessage"/>-based response.
 /// </typeparam>
 /// <param name="request">
 /// The <see cref="XmlMessage"/>-based request to convert and relay.
 /// </param>
 /// <param name="converter">
 /// The <see cref="IXmlMessageConverter"/> to use to convert the request and response.
 /// </param>
 /// <returns>
 /// The converted <see cref="XmlMessage"/>-based response.
 /// </returns>
 protected TResponse RelayRequest <TRequest, TResponse>(TRequest request, IXmlMessageConverter converter)
     where TRequest : XmlMessage
     where TResponse : XmlMessage, new()
 {
     return(RelayRequest <TRequest, TResponse>(request, relay => relay.Endpoint.Binding.SendTimeout, converter));
 }
 public IAsyncResult BeginRequest <TRequest>(TRequest xmlRequest, IXmlMessageConverter converter, AsyncCallback asyncCallback, object asyncState)
     where TRequest : XmlMessage
 {
     return(BeginRequest(xmlRequest, Endpoint.Binding !.SendTimeout, converter, asyncCallback, asyncState));
 }
        /// <summary>
        /// Converts and sends an <see cref="XmlMessage"/>-based request and, converts and returns the correlated <see
        /// cref="XmlMessage"/>-based response within a specified interval of time.
        /// </summary>
        /// <typeparam name="TRequest">
        /// The type of the <see cref="XmlMessage"/>-based request.
        /// </typeparam>
        /// <typeparam name="TResponse">
        /// The type of the <see cref="XmlMessage"/>-based response.
        /// </typeparam>
        /// <param name="xmlRequest">
        /// The <see cref="XmlMessage"/>-based request to convert and send.
        /// </param>
        /// <param name="timeout">
        /// The <see cref="TimeSpan"/> that specifies the interval of time within which a response must be received.
        /// </param>
        /// <param name="converter">
        /// The <see cref="IXmlMessageConverter"/> to use to convert the request and response.
        /// </param>
        /// <returns>
        /// The converted <see cref="XmlMessage"/>-based response.
        /// </returns>
        public TResponse Request <TRequest, TResponse>(TRequest xmlRequest, TimeSpan timeout, IXmlMessageConverter converter)
            where TRequest : XmlMessage
            where TResponse : XmlMessage, new()
        {
            if (xmlRequest == null)
            {
                throw new ArgumentNullException(nameof(xmlRequest));
            }
            if (converter == null)
            {
                throw new ArgumentNullException(nameof(converter));
            }

            using (var request = converter.CreateMessageRequestFromXmlRequest(xmlRequest))
                using (var response = Channel.Request(request, timeout))
                {
                    return(converter.CreateXmlResponseFromMessageResponse <TResponse>(response));
                }
        }
 public TResponse Request <TRequest, TResponse>(TRequest xmlRequest, IXmlMessageConverter converter)
     where TRequest : XmlMessage
     where TResponse : XmlMessage, new()
 {
     return(Request <TRequest, TResponse>(xmlRequest, Endpoint.Binding !.SendTimeout, converter));
 }