Example #1
0
        public IAsyncResult BeginRequest(Message message, TimeSpan timeout, AsyncCallback callback, object state)
        {
            if (message == null)
            {
                throw Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("message");
            }
            if (timeout < TimeSpan.Zero)
            {
                throw Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("timeout", (object)timeout, Microsoft.ServiceBus.SR.GetString(Resources.SFxTimeoutOutOfRange0, new object[0])));
            }
            base.ThrowIfDisposedOrNotOpen();
            this.AddHeadersTo(message);
            Microsoft.ServiceBus.Channels.IAsyncRequest asyncRequest = this.CreateAsyncRequest(message, callback, state);
            this.TrackRequest(asyncRequest);
            bool flag = true;

            try
            {
                asyncRequest.BeginSendRequest(message, timeout);
                flag = false;
            }
            finally
            {
                if (flag)
                {
                    this.ReleaseRequest(asyncRequest);
                }
            }
            return(asyncRequest);
        }
Example #2
0
        public Message EndRequest(IAsyncResult result)
        {
            Message message;

            if (result == null)
            {
                throw Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("result");
            }
            Microsoft.ServiceBus.Channels.IAsyncRequest asyncRequest = result as Microsoft.ServiceBus.Channels.IAsyncRequest;
            if (asyncRequest == null)
            {
                throw Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("result", Microsoft.ServiceBus.SR.GetString(Resources.InvalidAsyncResult, new object[0]));
            }
            try
            {
                Message message1 = asyncRequest.End();
                if (Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ShouldTraceInformation)
                {
                    TraceUtility.TraceEvent(TraceEventType.Information, TraceCode.RequestChannelReplyReceived, message1);
                }
                message = message1;
            }
            finally
            {
                this.ReleaseRequest(asyncRequest);
            }
            return(message);
        }