示例#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);
        }
示例#2
0
        /// <summary>
        /// Replies to a request message
        /// </summary>
        /// <param name="message">The incoming System.ServiceModel.Channels.Message that contains the request</param>
        public override void Reply(Message message)
        {
            if (message == null)
            {
                WCFLogger.Write(System.Diagnostics.TraceEventType.Information, "RequestContext received a null message. Shutting down.");
                return;
            }

            WCFLogger.Write(System.Diagnostics.TraceEventType.Start, "RequestContext starting to reply...");
            try {
                pMailHandler.Send(CreateMailMessage(message), _requestMessage.MessageId);
            }
            catch (Exception e) {
                _bindingElement.RaiseAsyncException(this, e);
                throw;
            }
            WCFLogger.Write(System.Diagnostics.TraceEventType.Stop, "RequestContext finished replying.");
        }