// public override IInputSessionChannel EndAcceptChannel(IAsyncResult result) { if (null == result) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("result"); } DoneReceivingAsyncResult doneRecevingResult = result as DoneReceivingAsyncResult; if (doneRecevingResult != null) { DoneReceivingAsyncResult.End(doneRecevingResult); return(null); } MsmqInputMessage msmqMessage = null; MsmqMessageProperty property = null; try { bool retval = this.receiver.EndTryReceive(result, out msmqMessage, out property); if (retval) { if (null != property) { return(MsmqDecodeHelper.DecodeTransportSessiongram(this, msmqMessage, property, this.receiveContextManager)); } else { if (CommunicationState.Opened == this.State) { this.Fault(); } return(null); } } else { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new TimeoutException()); } } catch (MsmqException ex) { if (ex.FaultReceiver) { this.Fault(); } throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(ex.Normalized); } finally { if (null != msmqMessage) { this.receiver.ReturnMessage(msmqMessage); } } }
// public override IInputSessionChannel AcceptChannel(TimeSpan timeout) { if (DoneReceivingInCurrentState()) { return(null); } if (!this.ReceiveParameters.ReceiveContextSettings.Enabled && (Transaction.Current == null)) { // In the absence of Receive context, Msmq Sessions can work only with the current transaction, this.Fault(); throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.MsmqTransactionRequired))); } MsmqInputMessage msmqMessage = this.receiver.TakeMessage(); try { MsmqMessageProperty property; bool retval = this.receiver.TryReceive(msmqMessage, timeout, MsmqTransactionMode.CurrentOrThrow, out property); if (retval) { if (null != property) { return(MsmqDecodeHelper.DecodeTransportSessiongram(this, msmqMessage, property, this.receiveContextManager)); } else { if (CommunicationState.Opened == this.State) { this.Fault(); } return(null); } } else { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new TimeoutException()); } } catch (MsmqException ex) { if (ex.FaultReceiver) { this.Fault(); } throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(ex.Normalized); } finally { this.receiver.ReturnMessage(msmqMessage); } }
public override IInputSessionChannel EndAcceptChannel(IAsyncResult result) { IInputSessionChannel channel; if (result == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("result"); } DoneReceivingAsyncResult result2 = result as DoneReceivingAsyncResult; if (result2 != null) { DoneReceivingAsyncResult.End(result2); return(null); } MsmqInputMessage msmqMessage = null; MsmqMessageProperty msmqProperty = null; try { if (!this.receiver.EndTryReceive(result, out msmqMessage, out msmqProperty)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new TimeoutException()); } if (msmqProperty != null) { return(MsmqDecodeHelper.DecodeTransportSessiongram(this, msmqMessage, msmqProperty, this.receiveContextManager)); } if (CommunicationState.Opened == base.State) { base.Fault(); } channel = null; } catch (MsmqException exception) { if (exception.FaultReceiver) { base.Fault(); } throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(exception.Normalized); } finally { if (msmqMessage != null) { this.receiver.ReturnMessage(msmqMessage); } } return(channel); }
public override IInputSessionChannel AcceptChannel(TimeSpan timeout) { IInputSessionChannel channel; if (base.DoneReceivingInCurrentState()) { return(null); } if (!base.ReceiveParameters.ReceiveContextSettings.Enabled && (Transaction.Current == null)) { base.Fault(); throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("MsmqTransactionRequired"))); } MsmqInputMessage msmqMessage = this.receiver.TakeMessage(); try { MsmqMessageProperty property; if (!this.receiver.TryReceive(msmqMessage, timeout, MsmqTransactionMode.CurrentOrThrow, out property)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new TimeoutException()); } if (property != null) { return(MsmqDecodeHelper.DecodeTransportSessiongram(this, msmqMessage, property, this.receiveContextManager)); } if (CommunicationState.Opened == base.State) { base.Fault(); } channel = null; } catch (MsmqException exception) { if (exception.FaultReceiver) { base.Fault(); } throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(exception.Normalized); } finally { this.receiver.ReturnMessage(msmqMessage); } return(channel); }