Ejemplo n.º 1
0
        public Message Receive(TimeSpan timeout)
        {
            Message message = null;

            if (DoneReceivingInCurrentState())
            {
                return(null);
            }

            bool shouldFault = true;

            try
            {
                message = MessageSource.Receive(timeout);
                OnReceiveMessage(message);
                shouldFault = false;
                return(message);
            }
            finally
            {
                if (shouldFault)
                {
                    if (message != null)
                    {
                        message.Close();
                        message = null;
                    }

                    Fault();
                }
            }
        }
Ejemplo n.º 2
0
        public void Send(Message message, TimeSpan timeout)
        {
            CorrelationCallbackMessageProperty callback = null;
            TimeoutHelper timeoutHelper = new TimeoutHelper(timeout);
            Message       sendMessage   = message;

            if (message != null)
            {
                this.ContextProtocol.OnOutgoingMessage(message, null);
                if (CorrelationCallbackMessageProperty.TryGet(message, out callback))
                {
                    ContextExchangeCorrelationHelper.AddOutgoingCorrelationCallbackData(callback, message, this.IsClient);
                    if (callback.IsFullyDefined)
                    {
                        sendMessage = callback.FinalizeCorrelation(message, timeoutHelper.RemainingTime());
                    }
                }
            }

            try
            {
                this.InnerChannel.Send(sendMessage, timeoutHelper.RemainingTime());
            }
            finally
            {
                if (message != null && !object.ReferenceEquals(message, sendMessage))
                {
                    sendMessage.Close();
                }
            }
        }
        public Message Request(Message message, TimeSpan timeout)
        {
            CorrelationCallbackMessageProperty property = null;
            TimeoutHelper helper   = new TimeoutHelper(timeout);
            Message       message2 = message;

            this.contextProtocol.OnOutgoingMessage(message, null);
            if ((message != null) && CorrelationCallbackMessageProperty.TryGet(message, out property))
            {
                ContextExchangeCorrelationHelper.AddOutgoingCorrelationCallbackData(property, message, true);
                if (property.IsFullyDefined)
                {
                    message2 = property.FinalizeCorrelation(message, helper.RemainingTime());
                }
            }
            Message message3 = null;

            try
            {
                message3 = base.InnerChannel.Request(message2, timeout);
                if (message3 != null)
                {
                    this.contextProtocol.OnIncomingMessage(message3);
                }
            }
            finally
            {
                if ((message != null) && !object.ReferenceEquals(message, message2))
                {
                    message2.Close();
                }
            }
            return(message3);
        }
Ejemplo n.º 4
0
        public async Task <Message> ReceiveAsync(TimeSpan timeout)
        {
            Message message = null;

            if (DoneReceivingInCurrentState())
            {
                return(null);
            }

            bool shouldFault = true;

            try
            {
                message = await _messageSource.ReceiveAsync(timeout);

                this.OnReceiveMessage(message);
                shouldFault = false;
                return(message);
            }
            finally
            {
                if (shouldFault)
                {
                    if (message != null)
                    {
                        message.Close();
                        message = null;
                    }

                    this.Fault();
                }
            }
        }
Ejemplo n.º 5
0
        public void InitiateHandShake()
        {
            IPeerNeighbor neighbor = host;
            Message       reply    = null;

            Fx.Assert(host != null, "Cannot initiate security handshake without a host!");

            //send the RST message.
            using (OperationContextScope scope = new OperationContextScope(new OperationContext((ServiceHostBase)null)))
            {
                PeerHashToken token   = this.securityManager.GetSelfToken();
                Message       request = Message.CreateMessage(MessageVersion.Soap12WSAddressing10, TrustFeb2005Strings.RequestSecurityToken, new PeerRequestSecurityToken(token));
                bool          fatal   = false;
                try
                {
                    reply = neighbor.RequestSecurityToken(request);

                    if (!(reply != null))
                    {
                        throw Fx.AssertAndThrow("SecurityHandshake return empty message!");
                    }
                    ProcessRstr(neighbor, reply, PeerSecurityManager.FindClaim(ServiceSecurityContext.Current));
                }
                catch (Exception e)
                {
                    if (Fx.IsFatal(e))
                    {
                        fatal = true;
                        throw;
                    }
                    DiagnosticUtility.TraceHandledException(e, TraceEventType.Information);
                    this.state = PeerAuthState.Failed;
                    if (DiagnosticUtility.ShouldTraceError)
                    {
                        ServiceSecurityContext context = ServiceSecurityContext.Current;
                        ClaimSet claimSet = null;
                        if (context != null && context.AuthorizationContext != null && context.AuthorizationContext.ClaimSets != null && context.AuthorizationContext.ClaimSets.Count > 0)
                        {
                            claimSet = context.AuthorizationContext.ClaimSets[0];
                        }
                        PeerAuthenticationFailureTraceRecord record = new PeerAuthenticationFailureTraceRecord(
                            meshId,
                            neighbor.ListenAddress.EndpointAddress.ToString(),
                            claimSet,
                            e);
                        TraceUtility.TraceEvent(TraceEventType.Error,
                                                TraceCode.PeerNodeAuthenticationFailure, SR.GetString(SR.TraceCodePeerNodeAuthenticationFailure),
                                                record, this, null);
                    }
                    neighbor.Abort(PeerCloseReason.AuthenticationFailure, PeerCloseInitiator.LocalNode);
                }
                finally
                {
                    if (!fatal)
                    {
                        request.Close();
                    }
                }
            }
        }
Ejemplo n.º 6
0
        public override void Reply(Message message, TimeSpan timeout)
        {
            TimeoutHelper helper   = new TimeoutHelper(timeout);
            Message       message2 = message;

            if (message != null)
            {
                CorrelationCallbackMessageProperty property;
                this.contextProtocol.OnOutgoingMessage(message, this);
                if (CorrelationCallbackMessageProperty.TryGet(message, out property))
                {
                    ContextExchangeCorrelationHelper.AddOutgoingCorrelationCallbackData(property, message, false);
                    if (property.IsFullyDefined)
                    {
                        message2 = property.FinalizeCorrelation(message, helper.RemainingTime());
                        message2.Properties.Remove(CorrelationCallbackMessageProperty.Name);
                    }
                }
            }
            try
            {
                this.innerContext.Reply(message2, helper.RemainingTime());
            }
            finally
            {
                if ((message != null) && !object.ReferenceEquals(message, message2))
                {
                    message2.Close();
                }
            }
        }
        private void ProcessCloseOrTerminateReply(bool close, Message reply)
        {
            if (reply == null)
            {
                throw Fx.AssertAndThrow("Argument reply cannot be null.");
            }
            ReliableRequestor requestor = close ? this.closeRequestor : this.terminateRequestor;

            if (requestor.GetInfo() == null)
            {
                try
                {
                    WsrmMessageInfo info = WsrmMessageInfo.Get(this.Settings.MessageVersion, this.Settings.ReliableMessagingVersion, this.binder.Channel, this.binder.GetInnerSession(), reply);
                    this.ReliableSession.ProcessInfo(info, null, true);
                    this.ReliableSession.VerifyDuplexProtocolElements(info, null, true);
                    WsrmFault fault = close ? WsrmUtilities.ValidateCloseSequenceResponse(this.session, requestor.MessageId, info, this.connection.Last) : WsrmUtilities.ValidateTerminateSequenceResponse(this.session, requestor.MessageId, info, this.connection.Last);
                    if (fault != null)
                    {
                        this.ReliableSession.OnLocalFault(null, fault, null);
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(fault.CreateException());
                    }
                }
                finally
                {
                    reply.Close();
                }
            }
        }
Ejemplo n.º 8
0
 private void ValidateResponse(Message response)
 {
     if (response != null)
     {
         if ((response.Version == MessageVersion.None) && (response is NullMessage))
         {
             response.Close();
         }
         else
         {
             Exception innerException = null;
             if (response.IsFault)
             {
                 try
                 {
                     innerException = new FaultException(MessageFault.CreateFault(response, 0x10000));
                 }
                 catch (Exception exception2)
                 {
                     if (Fx.IsFatal(exception2))
                     {
                         throw;
                     }
                     if ((!(exception2 is CommunicationException) && !(exception2 is TimeoutException)) && (!(exception2 is XmlException) && !(exception2 is IOException)))
                     {
                         throw;
                     }
                     innerException = exception2;
                 }
             }
             throw TraceUtility.ThrowHelperError(new ProtocolException(System.ServiceModel.SR.GetString("OneWayUnexpectedResponse"), innerException), response);
         }
     }
 }
Ejemplo n.º 9
0
        protected override void OnReply(Message message, TimeSpan timeout)
        {
            TimeoutHelper helper   = new TimeoutHelper(timeout);
            Message       message2 = null;

            message2 = message;
            try
            {
                bool flag = this.PrepareReply(ref message2);
                ThreadTrace.Trace("Begin sending http reply");
                this.httpOutput.Send(helper.RemainingTime());
                if (TD.MessageSentByTransportIsEnabled())
                {
                    TD.MessageSentByTransport(this.Listener.Uri.AbsoluteUri);
                }
                ThreadTrace.Trace("End sending http reply");
                if (flag)
                {
                    this.httpOutput.Close();
                }
            }
            finally
            {
                if ((message != null) && !object.ReferenceEquals(message, message2))
                {
                    message2.Close();
                }
            }
        }
Ejemplo n.º 10
0
        public override void ReadTransactionDataFromMessage(Message message, MessageDirection direction)
        {
            try
            {
                base.ReadTransactionDataFromMessage(message, direction);
            }
            catch (FaultException fault)
            {
                Message reply = Message.CreateMessage(message.Version, fault.CreateMessageFault(), fault.Action);

                System.ServiceModel.Channels.RequestReplyCorrelator.AddressReply(reply, message);
                System.ServiceModel.Channels.RequestReplyCorrelator.PrepareReply(reply, message.Headers.MessageId);

                try
                {
                    this.Send(reply);
                }
                finally
                {
                    reply.Close();
                }

                throw;
            }
        }
Ejemplo n.º 11
0
 private RequestContext FinishReceiveRequest(RequestContext innerContext, TimeSpan timeout)
 {
     if (innerContext == null)
     {
         return(null);
     }
     try
     {
         this.ReadTransactionDataFromMessage(innerContext.RequestMessage, MessageDirection.Input);
     }
     catch (FaultException exception)
     {
         string  action  = exception.Action ?? innerContext.RequestMessage.Version.Addressing.DefaultFaultAction;
         Message message = Message.CreateMessage(innerContext.RequestMessage.Version, exception.CreateMessageFault(), action);
         try
         {
             innerContext.Reply(message, timeout);
         }
         finally
         {
             message.Close();
         }
         throw;
     }
     return(new TransactionRequestContext(this, this, innerContext, this.DefaultCloseTimeout, base.DefaultSendTimeout));
 }
Ejemplo n.º 12
0
        public void Send(Message message, TimeSpan timeout)
        {
            CorrelationCallbackMessageProperty property = null;
            TimeoutHelper helper   = new TimeoutHelper(timeout);
            Message       message2 = message;

            if (message != null)
            {
                this.ContextProtocol.OnOutgoingMessage(message, null);
                if (CorrelationCallbackMessageProperty.TryGet(message, out property))
                {
                    ContextExchangeCorrelationHelper.AddOutgoingCorrelationCallbackData(property, message, this.IsClient);
                    if (property.IsFullyDefined)
                    {
                        message2 = property.FinalizeCorrelation(message, helper.RemainingTime());
                    }
                }
            }
            try
            {
                base.InnerChannel.Send(message2, helper.RemainingTime());
            }
            finally
            {
                if ((message != null) && !object.ReferenceEquals(message, message2))
                {
                    message2.Close();
                }
            }
        }
 public void OnLocalFault(Exception e, Message faultMessage, RequestContext context)
 {
     if ((this.channel.Aborted || (this.channel.State == CommunicationState.Faulted)) || (this.channel.State == CommunicationState.Closed))
     {
         if (faultMessage != null)
         {
             faultMessage.Close();
         }
         if (context != null)
         {
             context.Abort();
         }
     }
     else
     {
         lock (this.ThisLock)
         {
             if (this.faulted != SessionFaultState.NotFaulted)
             {
                 return;
             }
             this.faulted           = SessionFaultState.LocallyFaulted;
             this.terminatingFault  = faultMessage;
             this.replyFaultContext = context;
         }
         this.FaultCore();
         this.channel.Fault(e);
         this.UnblockChannelIfNecessary();
     }
 }
        public override void Reply(Message message, TimeSpan timeout)
        {
            TimeoutHelper timeoutHelper = new TimeoutHelper(timeout);
            Message       replyMessage  = message;

            if (message != null)
            {
                this.contextProtocol.OnOutgoingMessage(message, this);

                CorrelationCallbackMessageProperty callback;
                if (CorrelationCallbackMessageProperty.TryGet(message, out callback))
                {
                    ContextExchangeCorrelationHelper.AddOutgoingCorrelationCallbackData(callback, message, false);

                    if (callback.IsFullyDefined)
                    {
                        replyMessage = callback.FinalizeCorrelation(message, timeoutHelper.RemainingTime());
                        // we are done finalizing correlation, removing the messageproperty since we do not need it anymore
                        replyMessage.Properties.Remove(CorrelationCallbackMessageProperty.Name);
                    }
                }
            }

            try
            {
                this.innerContext.Reply(replyMessage, timeoutHelper.RemainingTime());
            }
            finally
            {
                if (message != null && !object.ReferenceEquals(message, replyMessage))
                {
                    replyMessage.Close();
                }
            }
        }
Ejemplo n.º 15
0
        protected override void OnReply(Message message, TimeSpan timeout)
        {
            TimeoutHelper timeoutHelper   = new TimeoutHelper(timeout);
            Message       responseMessage = message;

            try
            {
                bool closeOutputAfterReply = PrepareReply(ref responseMessage);
                this.httpPipeline.SendReply(responseMessage, timeoutHelper.RemainingTime());

                if (closeOutputAfterReply)
                {
                    httpOutput.Close();
                }

                if (TD.MessageSentByTransportIsEnabled())
                {
                    TD.MessageSentByTransport(eventTraceActivity, this.Listener.Uri.AbsoluteUri);
                }
            }
            finally
            {
                if (message != null &&
                    !object.ReferenceEquals(message, responseMessage))
                {
                    responseMessage.Close();
                }
            }
        }
        private Exception DeserializeFault(System.ServiceModel.Channels.Message inMessage, FaultConverter faultConverter)
        {
            MessageFault fault  = MessageFault.CreateFault(inMessage, 0x10000);
            string       action = inMessage.Headers.Action;

            if (action == inMessage.Version.Addressing.DefaultFaultAction)
            {
                action = null;
            }
            Exception exception = null;

            if (faultConverter != null)
            {
                faultConverter.TryCreateException(inMessage, fault, out exception);
            }
            if (exception == null)
            {
                exception = this.FaultFormatter.Deserialize(fault, action);
            }
            if (inMessage.State != MessageState.Created)
            {
                inMessage.Close();
            }
            return(exception);
        }
        private void SendMessageToNeighbor(IPeerNeighbor neighbor, Message message, PeerMessageHelpers.CleanupCallback cleanupCallback)
        {
            bool flag = false;

            try
            {
                neighbor.Send(message);
            }
            catch (Exception exception)
            {
                if (Fx.IsFatal(exception))
                {
                    flag = true;
                    throw;
                }
                if ((!(exception is CommunicationException) && !(exception is QuotaExceededException)) && (!(exception is ObjectDisposedException) && !(exception is TimeoutException)))
                {
                    throw;
                }
                DiagnosticUtility.ExceptionUtility.TraceHandledException(exception, TraceEventType.Information);
                if (cleanupCallback != null)
                {
                    cleanupCallback(neighbor, PeerCloseReason.InternalFailure, exception);
                }
            }
            finally
            {
                if (!flag)
                {
                    message.Close();
                }
            }
        }
        public Message Receive(TimeSpan timeout)
        {
            Message message = null;
            Message message2;

            if (base.DoneReceivingInCurrentState())
            {
                return(null);
            }
            bool flag = true;

            try
            {
                message = this.messageSource.Receive(timeout);
                this.OnReceiveMessage(message);
                flag     = false;
                message2 = message;
            }
            finally
            {
                if (flag)
                {
                    if (message != null)
                    {
                        message.Close();
                        message = null;
                    }
                    base.Fault();
                }
            }
            return(message2);
        }
        private void ProcessCloseOrTerminateReply(bool close, Message reply)
        {
            if (reply == null)
            {
                throw Fx.AssertAndThrow("Argument reply cannot be null.");
            }
            ReliableMessagingVersion reliableMessagingVersion = this.settings.ReliableMessagingVersion;

            if (reliableMessagingVersion == ReliableMessagingVersion.WSReliableMessagingFebruary2005)
            {
                if (close)
                {
                    throw Fx.AssertAndThrow("Close does not exist in Feb2005.");
                }
                reply.Close();
            }
            else
            {
                if (reliableMessagingVersion == ReliableMessagingVersion.WSReliableMessaging11)
                {
                    if (this.closeRequestor.GetInfo() != null)
                    {
                        return;
                    }
                    try
                    {
                        WsrmMessageInfo info = WsrmMessageInfo.Get(this.settings.MessageVersion, reliableMessagingVersion, this.binder.Channel, this.binder.GetInnerSession(), reply);
                        this.session.ProcessInfo(info, null, true);
                        this.session.VerifyDuplexProtocolElements(info, null, true);
                        WsrmFault fault = close ? WsrmUtilities.ValidateCloseSequenceResponse(this.session, this.closeRequestor.MessageId, info, this.connection.Last) : WsrmUtilities.ValidateTerminateSequenceResponse(this.session, this.terminateRequestor.MessageId, info, this.connection.Last);
                        if (fault != null)
                        {
                            this.session.OnLocalFault(null, fault, null);
                            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(fault.CreateException());
                        }
                        return;
                    }
                    finally
                    {
                        reply.Close();
                    }
                }
                throw Fx.AssertAndThrow("Reliable messaging version not supported.");
            }
        }
        internal static Message DecodeIntegrationDatagram(MsmqIntegrationChannelListener listener, MsmqReceiveHelper receiver, MsmqIntegrationInputMessage msmqMessage, MsmqMessageProperty messageProperty)
        {
            Message message2;

            using (MsmqDiagnostics.BoundReceiveBytesOperation())
            {
                Message message = Message.CreateMessage(MessageVersion.None, (string)null);
                bool    flag    = true;
                try
                {
                    SecurityMessageProperty property = listener.ValidateSecurity(msmqMessage);
                    if (property != null)
                    {
                        message.Properties.Security = property;
                    }
                    MsmqIntegrationMessageProperty property2 = new MsmqIntegrationMessageProperty();
                    msmqMessage.SetMessageProperties(property2);
                    int length = msmqMessage.BodyLength.Value;
                    if (length > listener.MaxReceivedMessageSize)
                    {
                        receiver.FinalDisposition(messageProperty);
                        throw listener.NormalizePoisonException(messageProperty.LookupId, MaxMessageSizeStream.CreateMaxReceivedMessageSizeExceededException(listener.MaxReceivedMessageSize));
                    }
                    byte[]       bufferCopy = msmqMessage.Body.GetBufferCopy(length);
                    MemoryStream bodyStream = new MemoryStream(bufferCopy, 0, bufferCopy.Length, false);
                    object       obj2       = null;
                    using (MsmqDiagnostics.BoundDecodeOperation())
                    {
                        try
                        {
                            obj2 = DeserializeForIntegration(listener, bodyStream, property2, messageProperty.LookupId);
                        }
                        catch (SerializationException exception)
                        {
                            receiver.FinalDisposition(messageProperty);
                            throw listener.NormalizePoisonException(messageProperty.LookupId, new ProtocolException(System.ServiceModel.SR.GetString("MsmqDeserializationError"), exception));
                        }
                        property2.Body = obj2;
                        message.Properties["MsmqIntegrationMessageProperty"] = property2;
                        bodyStream.Seek(0L, SeekOrigin.Begin);
                        message.Headers.To = listener.Uri;
                        flag = false;
                        MsmqDiagnostics.TransferFromTransport(message);
                    }
                    message2 = message;
                }
                finally
                {
                    if (flag)
                    {
                        message.Close();
                    }
                }
            }
            return(message2);
        }
Ejemplo n.º 21
0
 protected override void ProcessSequencedItem(IDuplexSessionChannel channel, Message message, ReliableInputSessionChannelOverDuplex reliableChannel, WsrmMessageInfo info, bool newChannel)
 {
     if (!newChannel && !reliableChannel.Binder.UseNewChannel(channel))
     {
         message.Close();
         channel.Abort();
     }
     else
     {
         reliableChannel.ProcessDemuxedMessage(info);
     }
 }
Ejemplo n.º 22
0
 private void SetRequestMessage(Message message, Exception requestException)
 {
     if (requestException != null)
     {
         base.SetRequestMessage(requestException);
         message.Close();
     }
     else
     {
         message.Properties.Security = (this.securityProperty != null) ? ((SecurityMessageProperty)this.securityProperty.CreateCopy()) : null;
         base.SetRequestMessage(message);
     }
 }
Ejemplo n.º 23
0
            private Message ProcessContext(RequestContext context, TimeSpan timeout)
            {
                if (context == null)
                {
                    return(null);
                }
                bool    flag           = false;
                Message requestMessage = null;

                try
                {
                    requestMessage = context.RequestMessage;
                    requestMessage.Properties.Add(RequestContextMessageProperty.Name, new RequestContextMessageProperty(context));
                    if (this.validateHeader)
                    {
                        PacketRoutableHeader.ValidateMessage(requestMessage);
                    }
                    try
                    {
                        context.Reply(null, new TimeoutHelper(timeout).RemainingTime());
                        flag = true;
                    }
                    catch (CommunicationException exception)
                    {
                        if (DiagnosticUtility.ShouldTraceInformation)
                        {
                            DiagnosticUtility.ExceptionUtility.TraceHandledException(exception, TraceEventType.Information);
                        }
                    }
                    catch (TimeoutException exception2)
                    {
                        if (DiagnosticUtility.ShouldTraceInformation)
                        {
                            DiagnosticUtility.ExceptionUtility.TraceHandledException(exception2, TraceEventType.Information);
                        }
                    }
                }
                finally
                {
                    if (!flag)
                    {
                        context.Abort();
                        if (requestMessage != null)
                        {
                            requestMessage.Close();
                            requestMessage = null;
                        }
                    }
                }
                return(requestMessage);
            }
 private bool EnqueueMessage(Message message)
 {
     if (this.validateHeader)
     {
         if (!PacketRoutableHeader.TryValidateMessage(message))
         {
             this.channel.Abort();
             message.Close();
             return(false);
         }
         this.validateHeader = false;
     }
     return(this.acceptor.EnqueueWithoutDispatch(message, this.onMessageDequeued));
 }
Ejemplo n.º 25
0
        public void InitiateHandShake()
        {
            IPeerNeighbor host    = this.host;
            Message       message = null;

            using (new OperationContextScope(new OperationContext(null)))
            {
                PeerHashToken selfToken = this.securityManager.GetSelfToken();
                Message       request   = Message.CreateMessage(MessageVersion.Soap12WSAddressing10, "RequestSecurityToken", (BodyWriter) new PeerRequestSecurityToken(selfToken));
                bool          flag      = false;
                try
                {
                    message = host.RequestSecurityToken(request);
                    if (message == null)
                    {
                        throw Fx.AssertAndThrow("SecurityHandshake return empty message!");
                    }
                    this.ProcessRstr(host, message, PeerSecurityManager.FindClaim(ServiceSecurityContext.Current));
                }
                catch (Exception exception)
                {
                    if (Fx.IsFatal(exception))
                    {
                        flag = true;
                        throw;
                    }
                    DiagnosticUtility.ExceptionUtility.TraceHandledException(exception, TraceEventType.Information);
                    this.state = PeerAuthState.Failed;
                    if (DiagnosticUtility.ShouldTraceError)
                    {
                        ServiceSecurityContext current = ServiceSecurityContext.Current;
                        ClaimSet claimSet = null;
                        if (((current != null) && (current.AuthorizationContext != null)) && ((current.AuthorizationContext.ClaimSets != null) && (current.AuthorizationContext.ClaimSets.Count > 0)))
                        {
                            claimSet = current.AuthorizationContext.ClaimSets[0];
                        }
                        PeerAuthenticationFailureTraceRecord extendedData = new PeerAuthenticationFailureTraceRecord(this.meshId, host.ListenAddress.EndpointAddress.ToString(), claimSet, exception);
                        TraceUtility.TraceEvent(TraceEventType.Error, 0x4004d, System.ServiceModel.SR.GetString("TraceCodePeerNodeAuthenticationFailure"), extendedData, this, null);
                    }
                    host.Abort(PeerCloseReason.AuthenticationFailure, PeerCloseInitiator.LocalNode);
                }
                finally
                {
                    if (!flag)
                    {
                        request.Close();
                    }
                }
            }
        }
Ejemplo n.º 26
0
 protected override void ProcessSequencedItem(IDuplexSessionChannel channel, Message message, ServerReliableDuplexSessionChannel reliableChannel, WsrmMessageInfo info, bool newChannel)
 {
     if (!newChannel)
     {
         IServerReliableChannelBinder binder = (IServerReliableChannelBinder)reliableChannel.Binder;
         if (!binder.UseNewChannel(channel))
         {
             message.Close();
             channel.Abort();
             return;
         }
     }
     reliableChannel.ProcessDemuxedMessage(info);
 }
Ejemplo n.º 27
0
 private string PeekAndRetrieveMessage(MessageBufferClient client)
 {
     System.ServiceModel.Channels.Message lockedMessage = client.PeekLock();
     try
     {
         client.DeleteLockedMessage(lockedMessage);
         return(lockedMessage.GetBody <string>());
     }
     finally
     {
         if (lockedMessage != null)
         {
             lockedMessage.Close();
         }
     }
 }
 public void Set(Message reply)
 {
     lock (this.ThisLock)
     {
         if (!this.set)
         {
             this.reply = reply;
             this.set   = true;
             return;
         }
     }
     if (reply != null)
     {
         reply.Close();
     }
 }
 private void UtilityMessageSent(IAsyncResult result)
 {
     if ((result != null) && (result.AsyncState != null))
     {
         IPeerNeighbor owner = this.owner;
         if (((owner != null) && PeerNeighborStateHelper.IsConnected(owner.State)) && !result.CompletedSynchronously)
         {
             AsyncUtilityState asyncState = (AsyncUtilityState)result.AsyncState;
             Message           message    = asyncState.message;
             UtilityInfo       umessage   = asyncState.info;
             bool flag = false;
             if (umessage == null)
             {
                 throw Fx.AssertAndThrow("expecting a UtilityInfo message in the AsyncState!");
             }
             try
             {
                 owner.EndSend(result);
             }
             catch (Exception exception)
             {
                 if (Fx.IsFatal(exception))
                 {
                     flag = true;
                     throw;
                 }
                 if (this.HandleSendException(owner, exception, umessage) != null)
                 {
                     throw;
                 }
                 DiagnosticUtility.ExceptionUtility.TraceHandledException(exception, TraceEventType.Information);
             }
             finally
             {
                 if (!flag)
                 {
                     message.Close();
                 }
             }
             EventHandler utilityInfoSent = this.UtilityInfoSent;
             if (utilityInfoSent != null)
             {
                 utilityInfoSent(this, EventArgs.Empty);
             }
         }
     }
 }
Ejemplo n.º 30
0
        void SendUtilityMessage(uint useful, uint total)
        {
            IPeerNeighbor host = owner;

            if (host == null || !PeerNeighborStateHelper.IsConnected(host.State) || total == 0)
            {
                return;
            }
            UtilityInfo  umessage = new UtilityInfo(useful, total);
            IAsyncResult result   = null;
            Message      message  = MessageConverter.ToMessage(umessage, MessageVersion.Soap12WSAddressing10);
            bool         fatal    = false;

            try
            {
                result = host.BeginSend(message, Fx.ThunkCallback(new AsyncCallback(UtilityMessageSent)), new AsyncUtilityState(message, umessage));
                if (result.CompletedSynchronously)
                {
                    host.EndSend(result);
                    EventHandler handler = UtilityInfoSent;
                    if (handler != null)
                    {
                        handler(this, EventArgs.Empty);
                    }
                }
            }
            catch (Exception e)
            {
                if (Fx.IsFatal(e))
                {
                    fatal = true;
                    throw;
                }
                if (null != HandleSendException(host, e, umessage))
                {
                    throw;
                }
                DiagnosticUtility.TraceHandledException(e, TraceEventType.Information);
            }
            finally
            {
                if (!fatal && (result == null || result.CompletedSynchronously))
                {
                    message.Close();
                }
            }
        }