コード例 #1
0
        /// <summary>
        /// The request
        /// </summary>
        /// <param name="message">The request System.ServiceModel.Channels.Message to be transmitted</param>
        /// <param name="timeout">The System.TimeSpan that specifies the interval of time within which a response
        /// must be received</param>
        /// <returns></returns>
        public Message Request(Message message, TimeSpan timeout)
        {
            WCFLogger.Write(TraceEventType.Start, "Mail request channel starting request");
            Message reply = null;

            ThrowIfDisposedOrNotOpen();

            // Send
            System.Diagnostics.Debug.Write("Mail requestChannel send request.");
            string id = _mailHandler.Send(CreateMailMessage(message));


            // If the message sent was a fault, don't expect a reply
            if (message.IsFault)
            {
                message.Close();
                WCFLogger.Write(TraceEventType.Stop, "Mail request channel finishing sending a fault");
                return(null);
            }

            try {
                // Wait for the reply
                AutoResetEvent onAbort = new AutoResetEvent(false);
                _threadsDequeueing.Add(onAbort);
                MailSoap12TransportBinding mail = _mailHandler.Dequeue(id, timeout, onAbort);


                // If dequeue returned null, someone stopped it, throw aborted exception
                if (mail == null)
                {
                    return(null);
                }

                // Get the WCF Message
                reply = mail.Attachment.WcfMessage;

                WCFLogger.Write(TraceEventType.Verbose, "Mail request channel got a reply");
            }
            catch (CommunicationObjectAbortedException) {
                message.Close();
                throw;
            }
            catch (TimeoutException) {
                message.Close();
                throw;
            }
            catch (Exception e) {
                this.Fault();
                message.Close();
                throw new EmailResponseNotGottenException(e);
            }

            WCFLogger.Write(TraceEventType.Stop, "Mail request channel finishing requesting");
            return(reply);
        }