private void DisposeRequestContext(System.ServiceModel.Channels.RequestContext context) { try { context.Close(); ReceiveContextRPCFacet receiveContext = this.ReceiveContext; if (receiveContext != null) { this.ReceiveContext = null; CallbackState state = new CallbackState { ChannelHandler = this.channelHandler, ReceiveContext = receiveContext }; IAsyncResult result = receiveContext.BeginComplete(TimeSpan.MaxValue, null, this.channelHandler, handleEndComplete, state); if (result.CompletedSynchronously) { receiveContext.EndComplete(result); } } } catch (Exception exception) { if (Fx.IsFatal(exception)) { throw; } this.AbortRequestContext(context); this.channelHandler.HandleError(exception); } }
protected override void OnClose(TimeSpan timeout) { DateTime start = DateTime.Now; if (reqctx != null) { reqctx.Close(timeout); } // FIXME: consider timeout AbortConnections(timeout - (DateTime.Now - start)); base.OnClose(timeout - (DateTime.Now - start)); }
protected override void OnClose(TimeSpan timeout) { DateTime start = DateTime.Now; if (reqctx != null) { reqctx.Close(timeout); } // FIXME: consider timeout lock (waiting) foreach (HttpListenerContext ctx in waiting) { ctx.Response.Close(); } base.OnClose(timeout - (DateTime.Now - start)); }
void IDisposable.Dispose() { RequestContext context; bool flag = false; lock (this.thisLock) { if (this.context == null) { return; } context = this.context; this.context = null; } try { context.Close(); 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(); } } }
void IDisposable.Dispose() { RequestContext context; bool flag = false; lock (this.thisLock) { if (this.context == null) { return; } context = this.context; this.context = null; } try { context.Close(); 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(); } } }
public bool ProcessInfo(WsrmMessageInfo info, RequestContext context, bool throwException) { Exception e; if (info.ParsingException != null) { WsrmFault fault; if (this.SequenceID != null) { string reason = SR.GetString(SR.CouldNotParseWithAction, info.Action); fault = SequenceTerminatedFault.CreateProtocolFault(this.SequenceID, reason, null); } else { fault = null; } e = new ProtocolException(SR.GetString(SR.MessageExceptionOccurred), info.ParsingException); this.OnLocalFault(throwException ? null : e, fault, context); } else if (info.FaultReply != null) { e = info.FaultException; this.OnLocalFault(throwException ? null : e, info.FaultReply, context); } else if ((info.WsrmHeaderFault != null) && (info.WsrmHeaderFault.SequenceID != this.InputID) && (info.WsrmHeaderFault.SequenceID != this.OutputID)) { e = new ProtocolException(SR.GetString(SR.WrongIdentifierFault, FaultException.GetSafeReasonText(info.WsrmHeaderFault.Reason))); this.OnLocalFault(throwException ? null : e, (Message)null, context); } else if (info.FaultInfo != null) { if (this.isSessionClosed) { UnknownSequenceFault unknownSequenceFault = info.FaultInfo as UnknownSequenceFault; if (unknownSequenceFault != null) { UniqueId sequenceId = unknownSequenceFault.SequenceID; if (((this.OutputID != null) && (this.OutputID == sequenceId)) || ((this.InputID != null) && (this.InputID == sequenceId))) { if (this.settings.ReliableMessagingVersion == ReliableMessagingVersion.WSReliableMessagingFebruary2005) { info.Message.Close(); return false; } else if (this.settings.ReliableMessagingVersion == ReliableMessagingVersion.WSReliableMessaging11) { return true; } else { throw Fx.AssertAndThrow("Unknown version."); } } } } e = info.FaultException; if (context != null) context.Close(); this.OnRemoteFault(throwException ? null : e); } else { return true; } info.Message.Close(); if (throwException) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(e); else return false; }
private void ProcessRequest(RequestContext context, WsrmMessageInfo info) { bool flag = true; bool flag2 = true; try { EndpointAddress address; bool flag3; if (!base.ReliableSession.ProcessInfo(info, context)) { flag = false; flag2 = false; return; } if (!base.ReliableSession.VerifySimplexProtocolElements(info, context)) { flag = false; flag2 = false; return; } base.ReliableSession.OnRemoteActivity(false); if (info.CreateSequenceInfo == null) { goto Label_0104; } if (WsrmUtilities.ValidateCreateSequence <IInputSessionChannel>(info, base.Listener, base.Binder.Channel, out address)) { Message response = WsrmUtilities.CreateCreateSequenceResponse(base.Listener.MessageVersion, base.Listener.ReliableMessagingVersion, false, info.CreateSequenceInfo, base.Listener.Ordered, base.ReliableSession.InputID, address); using (context) { using (response) { if (base.Binder.AddressResponse(info.Message, response)) { context.Reply(response, base.DefaultSendTimeout); } } goto Label_00FB; } } base.ReliableSession.OnLocalFault(info.FaultException, info.FaultReply, context); Label_00FB: flag = false; flag2 = false; return; Label_0104: flag3 = false; bool allAdded = false; bool flag5 = false; WsrmFault fault = null; Message message2 = null; Exception e = null; bool flag6 = base.Listener.ReliableMessagingVersion == ReliableMessagingVersion.WSReliableMessagingFebruary2005; bool flag7 = base.Listener.ReliableMessagingVersion == ReliableMessagingVersion.WSReliableMessaging11; bool flag8 = info.AckRequestedInfo != null; if (info.SequencedMessageInfo != null) { lock (base.ThisLock) { if (base.Aborted || (base.State == CommunicationState.Faulted)) { return; } long sequenceNumber = info.SequencedMessageInfo.SequenceNumber; bool isLast = flag6 && info.SequencedMessageInfo.LastMessage; if (!base.Connection.IsValid(sequenceNumber, isLast)) { if (flag6) { fault = new LastMessageNumberExceededFault(base.ReliableSession.InputID); } else { message2 = new SequenceClosedFault(base.ReliableSession.InputID).CreateMessage(base.Listener.MessageVersion, base.Listener.ReliableMessagingVersion); if (PerformanceCounters.PerformanceCountersEnabled) { PerformanceCounters.MessageDropped(base.perfCounterId); } } } else if (base.Connection.Ranges.Contains(sequenceNumber)) { if (PerformanceCounters.PerformanceCountersEnabled) { PerformanceCounters.MessageDropped(base.perfCounterId); } } else if (flag6 && (info.Action == "http://schemas.xmlsoap.org/ws/2005/02/rm/LastMessage")) { base.Connection.Merge(sequenceNumber, isLast); allAdded = base.Connection.AllAdded; } else if (base.State == CommunicationState.Closing) { if (flag6) { fault = SequenceTerminatedFault.CreateProtocolFault(base.ReliableSession.InputID, System.ServiceModel.SR.GetString("SequenceTerminatedSessionClosedBeforeDone"), System.ServiceModel.SR.GetString("SessionClosedBeforeDone")); } else { message2 = new SequenceClosedFault(base.ReliableSession.InputID).CreateMessage(base.Listener.MessageVersion, base.Listener.ReliableMessagingVersion); if (PerformanceCounters.PerformanceCountersEnabled) { PerformanceCounters.MessageDropped(base.perfCounterId); } } } else if (base.DeliveryStrategy.CanEnqueue(sequenceNumber) && (base.Listener.Ordered || base.Connection.CanMerge(sequenceNumber))) { base.Connection.Merge(sequenceNumber, isLast); flag3 = base.DeliveryStrategy.Enqueue(info.Message, sequenceNumber); allAdded = base.Connection.AllAdded; flag2 = false; } else if (PerformanceCounters.PerformanceCountersEnabled) { PerformanceCounters.MessageDropped(base.perfCounterId); } goto Label_05CE; } } if (flag6 && (info.TerminateSequenceInfo != null)) { bool flag11; lock (base.ThisLock) { flag11 = !base.Connection.Terminate(); } if (!flag11) { return; } fault = SequenceTerminatedFault.CreateProtocolFault(base.ReliableSession.InputID, System.ServiceModel.SR.GetString("SequenceTerminatedEarlyTerminateSequence"), System.ServiceModel.SR.GetString("EarlyTerminateSequence")); } else if (flag7 && ((info.TerminateSequenceInfo != null) || (info.CloseSequenceInfo != null))) { bool flag13 = info.TerminateSequenceInfo != null; WsrmRequestInfo info2 = flag13 ? ((WsrmRequestInfo)info.TerminateSequenceInfo) : ((WsrmRequestInfo)info.CloseSequenceInfo); long last = flag13 ? info.TerminateSequenceInfo.LastMsgNumber : info.CloseSequenceInfo.LastMsgNumber; if (!WsrmUtilities.ValidateWsrmRequest(base.ReliableSession, info2, base.Binder, context)) { flag2 = false; flag = false; return; } bool isLastLargeEnough = true; bool flag15 = true; lock (base.ThisLock) { if (!base.Connection.IsLastKnown) { if (flag13) { if (base.Connection.SetTerminateSequenceLast(last, out isLastLargeEnough)) { allAdded = true; } else if (isLastLargeEnough) { e = new ProtocolException(System.ServiceModel.SR.GetString("EarlyTerminateSequence")); } } else { allAdded = base.Connection.SetCloseSequenceLast(last); isLastLargeEnough = allAdded; } if (allAdded) { base.ReliableSession.SetFinalAck(base.Connection.Ranges); base.DeliveryStrategy.Dispose(); } } else { flag15 = last == base.Connection.Last; if ((flag13 && flag15) && base.Connection.IsSequenceClosed) { flag5 = true; } } } if (!isLastLargeEnough) { fault = SequenceTerminatedFault.CreateProtocolFault(base.ReliableSession.InputID, System.ServiceModel.SR.GetString("SequenceTerminatedSmallLastMsgNumber"), System.ServiceModel.SR.GetString("SmallLastMsgNumberExceptionString")); } else if (!flag15) { fault = SequenceTerminatedFault.CreateProtocolFault(base.ReliableSession.InputID, System.ServiceModel.SR.GetString("SequenceTerminatedInconsistentLastMsgNumber"), System.ServiceModel.SR.GetString("InconsistentLastMsgNumberExceptionString")); } else { message2 = flag13 ? WsrmUtilities.CreateTerminateResponseMessage(base.Listener.MessageVersion, info2.MessageId, base.ReliableSession.InputID) : WsrmUtilities.CreateCloseSequenceResponse(base.Listener.MessageVersion, info2.MessageId, base.ReliableSession.InputID); flag8 = true; } } Label_05CE: if (fault != null) { base.ReliableSession.OnLocalFault(fault.CreateException(), fault, context); flag2 = false; flag = false; } else { if ((message2 != null) && flag8) { base.AddAcknowledgementHeader(message2); } else if (message2 == null) { message2 = base.CreateAcknowledgmentMessage(); } using (message2) { context.Reply(message2); } if (flag5) { lock (base.ThisLock) { base.Connection.Terminate(); } } if (e != null) { base.ReliableSession.OnRemoteFault(e); } else { if (flag3) { base.Dispatch(); } if (allAdded) { ActionItem.Schedule(new Action <object>(this.ShutdownCallback), null); } } } } finally { if (flag2) { info.Message.Close(); } if (flag) { context.Close(); } } }
private void DisposeRequestContext(RequestContext context) { try { context.Close(); } catch (Exception e) { if (Fx.IsFatal(e)) { throw; } this.AbortRequestContext(context); this.channelHandler.HandleError(e); } }
public override void Close(TimeSpan timeout) { source.Close(timeout); }
private bool TryRetrievingInstanceContext(RequestContext request) { bool flag = true; try { if (!this.requestInfo.EndpointLookupDone) { this.EnsureChannelAndEndpoint(request); } if (this.requestInfo.Channel != null) { if (this.requestInfo.DispatchRuntime != null) { IContextChannel proxy = this.requestInfo.Channel.Proxy as IContextChannel; try { this.requestInfo.ExistingInstanceContext = this.requestInfo.DispatchRuntime.InstanceContextProvider.GetExistingInstanceContext(request.RequestMessage, proxy); flag = false; goto Label_00F2; } catch (Exception exception) { if (Fx.IsFatal(exception)) { throw; } this.requestInfo.Channel = null; this.HandleError(exception, request, this.channel); return false; } } TraceUtility.TraceDroppedMessage(request.RequestMessage, this.requestInfo.Endpoint); request.Close(); } return false; } catch (Exception exception2) { if (Fx.IsFatal(exception2)) { throw; } this.HandleError(exception2, request, this.channel); return false; } finally { if (flag) { this.ReleasePump(); } } Label_00F2: return true; }
void EnsureChannelAndEndpoint(RequestContext request) { this.requestInfo.Channel = this.channel; if (this.requestInfo.Channel == null) { bool addressMatched; if (this.hasSession) { this.requestInfo.Channel = this.GetSessionChannel(request.RequestMessage, out this.requestInfo.Endpoint, out addressMatched); } else { this.requestInfo.Channel = this.GetDatagramChannel(request.RequestMessage, out this.requestInfo.Endpoint, out addressMatched); } if (this.requestInfo.Channel == null) { this.host.RaiseUnknownMessageReceived(request.RequestMessage); if (addressMatched) { this.ReplyContractFilterDidNotMatch(request); } else { this.ReplyAddressFilterDidNotMatch(request); } } } else { this.requestInfo.Endpoint = this.requestInfo.Channel.EndpointDispatcher; //For sessionful contracts, the InstanceContext throttle is not copied over to the channel //as we create the channel before acquiring the lock if (this.InstanceContextServiceThrottle != null && this.requestInfo.Channel.InstanceContextServiceThrottle == null) { this.requestInfo.Channel.InstanceContextServiceThrottle = this.InstanceContextServiceThrottle; } } this.requestInfo.EndpointLookupDone = true; if (this.requestInfo.Channel == null) { // SFx drops a message here TraceUtility.TraceDroppedMessage(request.RequestMessage, this.requestInfo.Endpoint); request.Close(); return; } if (this.requestInfo.Channel.HasSession || this.isCallback) { this.requestInfo.DispatchRuntime = this.requestInfo.Channel.DispatchRuntime; } else { this.requestInfo.DispatchRuntime = this.requestInfo.Endpoint.DispatchRuntime; } }
private void ProcessRequest(RequestContext context, WsrmMessageInfo info) { bool flag = true; bool flag2 = true; try { EndpointAddress address; bool flag3; if (!base.ReliableSession.ProcessInfo(info, context)) { flag = false; flag2 = false; return; } if (!base.ReliableSession.VerifySimplexProtocolElements(info, context)) { flag = false; flag2 = false; return; } base.ReliableSession.OnRemoteActivity(false); if (info.CreateSequenceInfo == null) { goto Label_0104; } if (WsrmUtilities.ValidateCreateSequence<IInputSessionChannel>(info, base.Listener, base.Binder.Channel, out address)) { Message response = WsrmUtilities.CreateCreateSequenceResponse(base.Listener.MessageVersion, base.Listener.ReliableMessagingVersion, false, info.CreateSequenceInfo, base.Listener.Ordered, base.ReliableSession.InputID, address); using (context) { using (response) { if (base.Binder.AddressResponse(info.Message, response)) { context.Reply(response, base.DefaultSendTimeout); } } goto Label_00FB; } } base.ReliableSession.OnLocalFault(info.FaultException, info.FaultReply, context); Label_00FB: flag = false; flag2 = false; return; Label_0104: flag3 = false; bool allAdded = false; bool flag5 = false; WsrmFault fault = null; Message message2 = null; Exception e = null; bool flag6 = base.Listener.ReliableMessagingVersion == ReliableMessagingVersion.WSReliableMessagingFebruary2005; bool flag7 = base.Listener.ReliableMessagingVersion == ReliableMessagingVersion.WSReliableMessaging11; bool flag8 = info.AckRequestedInfo != null; if (info.SequencedMessageInfo != null) { lock (base.ThisLock) { if (base.Aborted || (base.State == CommunicationState.Faulted)) { return; } long sequenceNumber = info.SequencedMessageInfo.SequenceNumber; bool isLast = flag6 && info.SequencedMessageInfo.LastMessage; if (!base.Connection.IsValid(sequenceNumber, isLast)) { if (flag6) { fault = new LastMessageNumberExceededFault(base.ReliableSession.InputID); } else { message2 = new SequenceClosedFault(base.ReliableSession.InputID).CreateMessage(base.Listener.MessageVersion, base.Listener.ReliableMessagingVersion); if (PerformanceCounters.PerformanceCountersEnabled) { PerformanceCounters.MessageDropped(base.perfCounterId); } } } else if (base.Connection.Ranges.Contains(sequenceNumber)) { if (PerformanceCounters.PerformanceCountersEnabled) { PerformanceCounters.MessageDropped(base.perfCounterId); } } else if (flag6 && (info.Action == "http://schemas.xmlsoap.org/ws/2005/02/rm/LastMessage")) { base.Connection.Merge(sequenceNumber, isLast); allAdded = base.Connection.AllAdded; } else if (base.State == CommunicationState.Closing) { if (flag6) { fault = SequenceTerminatedFault.CreateProtocolFault(base.ReliableSession.InputID, System.ServiceModel.SR.GetString("SequenceTerminatedSessionClosedBeforeDone"), System.ServiceModel.SR.GetString("SessionClosedBeforeDone")); } else { message2 = new SequenceClosedFault(base.ReliableSession.InputID).CreateMessage(base.Listener.MessageVersion, base.Listener.ReliableMessagingVersion); if (PerformanceCounters.PerformanceCountersEnabled) { PerformanceCounters.MessageDropped(base.perfCounterId); } } } else if (base.DeliveryStrategy.CanEnqueue(sequenceNumber) && (base.Listener.Ordered || base.Connection.CanMerge(sequenceNumber))) { base.Connection.Merge(sequenceNumber, isLast); flag3 = base.DeliveryStrategy.Enqueue(info.Message, sequenceNumber); allAdded = base.Connection.AllAdded; flag2 = false; } else if (PerformanceCounters.PerformanceCountersEnabled) { PerformanceCounters.MessageDropped(base.perfCounterId); } goto Label_05CE; } } if (flag6 && (info.TerminateSequenceInfo != null)) { bool flag11; lock (base.ThisLock) { flag11 = !base.Connection.Terminate(); } if (!flag11) { return; } fault = SequenceTerminatedFault.CreateProtocolFault(base.ReliableSession.InputID, System.ServiceModel.SR.GetString("SequenceTerminatedEarlyTerminateSequence"), System.ServiceModel.SR.GetString("EarlyTerminateSequence")); } else if (flag7 && ((info.TerminateSequenceInfo != null) || (info.CloseSequenceInfo != null))) { bool flag13 = info.TerminateSequenceInfo != null; WsrmRequestInfo info2 = flag13 ? ((WsrmRequestInfo) info.TerminateSequenceInfo) : ((WsrmRequestInfo) info.CloseSequenceInfo); long last = flag13 ? info.TerminateSequenceInfo.LastMsgNumber : info.CloseSequenceInfo.LastMsgNumber; if (!WsrmUtilities.ValidateWsrmRequest(base.ReliableSession, info2, base.Binder, context)) { flag2 = false; flag = false; return; } bool isLastLargeEnough = true; bool flag15 = true; lock (base.ThisLock) { if (!base.Connection.IsLastKnown) { if (flag13) { if (base.Connection.SetTerminateSequenceLast(last, out isLastLargeEnough)) { allAdded = true; } else if (isLastLargeEnough) { e = new ProtocolException(System.ServiceModel.SR.GetString("EarlyTerminateSequence")); } } else { allAdded = base.Connection.SetCloseSequenceLast(last); isLastLargeEnough = allAdded; } if (allAdded) { base.ReliableSession.SetFinalAck(base.Connection.Ranges); base.DeliveryStrategy.Dispose(); } } else { flag15 = last == base.Connection.Last; if ((flag13 && flag15) && base.Connection.IsSequenceClosed) { flag5 = true; } } } if (!isLastLargeEnough) { fault = SequenceTerminatedFault.CreateProtocolFault(base.ReliableSession.InputID, System.ServiceModel.SR.GetString("SequenceTerminatedSmallLastMsgNumber"), System.ServiceModel.SR.GetString("SmallLastMsgNumberExceptionString")); } else if (!flag15) { fault = SequenceTerminatedFault.CreateProtocolFault(base.ReliableSession.InputID, System.ServiceModel.SR.GetString("SequenceTerminatedInconsistentLastMsgNumber"), System.ServiceModel.SR.GetString("InconsistentLastMsgNumberExceptionString")); } else { message2 = flag13 ? WsrmUtilities.CreateTerminateResponseMessage(base.Listener.MessageVersion, info2.MessageId, base.ReliableSession.InputID) : WsrmUtilities.CreateCloseSequenceResponse(base.Listener.MessageVersion, info2.MessageId, base.ReliableSession.InputID); flag8 = true; } } Label_05CE: if (fault != null) { base.ReliableSession.OnLocalFault(fault.CreateException(), fault, context); flag2 = false; flag = false; } else { if ((message2 != null) && flag8) { base.AddAcknowledgementHeader(message2); } else if (message2 == null) { message2 = base.CreateAcknowledgmentMessage(); } using (message2) { context.Reply(message2); } if (flag5) { lock (base.ThisLock) { base.Connection.Terminate(); } } if (e != null) { base.ReliableSession.OnRemoteFault(e); } else { if (flag3) { base.Dispatch(); } if (allAdded) { ActionItem.Schedule(new Action<object>(this.ShutdownCallback), null); } } } } finally { if (flag2) { info.Message.Close(); } if (flag) { context.Close(); } } }
bool HandleRequest(IReplyChannel channel, RequestContext context) { if (context == null) { channel.Close(); return false; } try { serviceManager.HandleRequest(context); } catch (CommunicationException) { context.Abort(); } finally { context.Close(); } return true; }
internal static void CloseReplySessionChannel(ReliableChannelBinder <IReplySessionChannel> binder, IReplySessionChannel channel, TimeSpan timeout) { TimeoutHelper timeoutHelper = new TimeoutHelper(timeout); binder.WaitForPendingOperations(timeoutHelper.RemainingTime()); TimeSpan timeout1 = timeoutHelper.RemainingTime(); bool flag1 = timeout1 == TimeSpan.Zero; while (true) { RequestContext context = (RequestContext)null; bool flag2 = true; try { bool request = channel.TryReceiveRequest(timeout1, out context); flag2 = false; if (request) { if (context == null) { channel.Close(timeoutHelper.RemainingTime()); return; } } } catch (Exception ex) { if (Fx.IsFatal(ex)) { throw; } else if (flag2) { if (!ReliableChannelBinderHelper.MaskHandled(binder.DefaultMaskingMode) || !binder.IsHandleable(ex)) { throw; } else { flag2 = false; } } else { throw; } } finally { if (context != null) { context.RequestMessage.Close(); context.Close(); } if (flag2) { channel.Abort(); } } if (!flag1 && channel.State == CommunicationState.Opened) { timeout1 = timeoutHelper.RemainingTime(); flag1 = timeout1 == TimeSpan.Zero; } else { break; } } channel.Abort(); }
public bool ProcessInfo(WsrmMessageInfo info, RequestContext context, bool throwException) { Exception faultException; if (info.ParsingException != null) { WsrmFault fault; if (this.SequenceID != null) { string faultReason = System.ServiceModel.SR.GetString("CouldNotParseWithAction", new object[] { info.Action }); fault = SequenceTerminatedFault.CreateProtocolFault(this.SequenceID, faultReason, null); } else { fault = null; } faultException = new ProtocolException(System.ServiceModel.SR.GetString("MessageExceptionOccurred"), info.ParsingException); this.OnLocalFault(throwException ? null : faultException, fault, context); } else if (info.FaultReply != null) { faultException = info.FaultException; this.OnLocalFault(throwException ? null : faultException, info.FaultReply, context); } else if (((info.WsrmHeaderFault != null) && (info.WsrmHeaderFault.SequenceID != this.InputID)) && (info.WsrmHeaderFault.SequenceID != this.OutputID)) { faultException = new ProtocolException(System.ServiceModel.SR.GetString("WrongIdentifierFault", new object[] { FaultException.GetSafeReasonText(info.WsrmHeaderFault.Reason) })); this.OnLocalFault(throwException ? null : faultException, (Message)null, context); } else { if (info.FaultInfo == null) { return(true); } if (this.isSessionClosed) { UnknownSequenceFault faultInfo = info.FaultInfo as UnknownSequenceFault; if (faultInfo != null) { UniqueId sequenceID = faultInfo.SequenceID; if (((this.OutputID != null) && (this.OutputID == sequenceID)) || ((this.InputID != null) && (this.InputID == sequenceID))) { if (this.settings.ReliableMessagingVersion == ReliableMessagingVersion.WSReliableMessagingFebruary2005) { info.Message.Close(); return(false); } if (this.settings.ReliableMessagingVersion != ReliableMessagingVersion.WSReliableMessaging11) { throw Fx.AssertAndThrow("Unknown version."); } return(true); } } } faultException = info.FaultException; if (context != null) { context.Close(); } this.OnRemoteFault(throwException ? null : faultException); } info.Message.Close(); if (throwException) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(faultException); } return(false); }
private bool HandleError(Exception e, RequestContext request, ServiceChannel channel) { bool flag; ErrorHandlerFaultInfo faultInfo = new ErrorHandlerFaultInfo(this.messageVersion.Addressing.DefaultFaultAction); this.ProvideFaultAndReplyFailure(request, e, ref faultInfo, out flag); if (flag) { try { request.Close(); } catch (Exception exception) { if (Fx.IsFatal(exception)) { throw; } this.HandleError(exception); } } else { request.Abort(); } if (!this.HandleError(e, ref faultInfo) && this.hasSession) { if (channel != null) { if (flag) { TimeoutHelper helper = new TimeoutHelper(CloseAfterFaultTimeout); try { channel.Close(helper.RemainingTime()); } catch (Exception exception2) { if (Fx.IsFatal(exception2)) { throw; } this.HandleError(exception2); } try { this.binder.CloseAfterFault(helper.RemainingTime()); goto Label_0117; } catch (Exception exception3) { if (Fx.IsFatal(exception3)) { throw; } this.HandleError(exception3); goto Label_0117; } } channel.Abort(); this.binder.Abort(); } else { if (flag) { try { this.binder.CloseAfterFault(CloseAfterFaultTimeout); goto Label_0117; } catch (Exception exception4) { if (Fx.IsFatal(exception4)) { throw; } this.HandleError(exception4); goto Label_0117; } } this.binder.Abort(); } } Label_0117: return true; }
private void EnsureChannelAndEndpoint(RequestContext request) { this.requestInfo.Channel = this.channel; if (this.requestInfo.Channel == null) { bool flag; if (this.hasSession) { this.requestInfo.Channel = this.GetSessionChannel(request.RequestMessage, out this.requestInfo.Endpoint, out flag); } else { this.requestInfo.Channel = this.GetDatagramChannel(request.RequestMessage, out this.requestInfo.Endpoint, out flag); } if (this.requestInfo.Channel == null) { this.host.RaiseUnknownMessageReceived(request.RequestMessage); if (flag) { this.ReplyContractFilterDidNotMatch(request); } else { this.ReplyAddressFilterDidNotMatch(request); } } } else { this.requestInfo.Endpoint = this.requestInfo.Channel.EndpointDispatcher; if ((this.InstanceContextServiceThrottle != null) && (this.requestInfo.Channel.InstanceContextServiceThrottle == null)) { this.requestInfo.Channel.InstanceContextServiceThrottle = this.InstanceContextServiceThrottle; } } this.requestInfo.EndpointLookupDone = true; if (this.requestInfo.Channel == null) { TraceUtility.TraceDroppedMessage(request.RequestMessage, this.requestInfo.Endpoint); request.Close(); } else if (this.requestInfo.Channel.HasSession || this.isCallback) { this.requestInfo.DispatchRuntime = this.requestInfo.Channel.DispatchRuntime; } else { this.requestInfo.DispatchRuntime = this.requestInfo.Endpoint.DispatchRuntime; } }
bool TryRetrievingInstanceContext(RequestContext request) { try { return TryRetrievingInstanceContextCore(request); } catch (Exception ex) { if (Fx.IsFatal(ex)) { throw; } DiagnosticUtility.TraceHandledException(ex, TraceEventType.Error); try { request.Close(); } catch (Exception e) { if (Fx.IsFatal(e)) { throw; } request.Abort(); } return false; } }
//Return: False denotes failure, Caller should discard the request. // : True denotes operation is sucessful. bool TryRetrievingInstanceContextCore(RequestContext request) { bool releasePump = true; try { if (!this.requestInfo.EndpointLookupDone) { this.EnsureChannelAndEndpoint(request); } if (this.requestInfo.Channel == null) { return false; } if (this.requestInfo.DispatchRuntime != null) { IContextChannel transparentProxy = this.requestInfo.Channel.Proxy as IContextChannel; try { this.requestInfo.ExistingInstanceContext = this.requestInfo.DispatchRuntime.InstanceContextProvider.GetExistingInstanceContext(request.RequestMessage, transparentProxy); releasePump = false; } catch (Exception e) { if (Fx.IsFatal(e)) { throw; } this.requestInfo.Channel = null; this.HandleError(e, request, channel); return false; } } else { // This can happen if we are pumping for an async client, // and we receive a bogus reply. In that case, there is no // DispatchRuntime, because we are only expecting replies. // // One possible fix for this would be in DuplexChannelBinder // to drop all messages with a RelatesTo that do not match a // pending request. // // However, that would not fix: // (a) we could get a valid request message with a // RelatesTo that we should try to process. // (b) we could get a reply message that does not have // a RelatesTo. // // So we do the null check here. // // SFx drops a message here TraceUtility.TraceDroppedMessage(request.RequestMessage, this.requestInfo.Endpoint); request.Close(); return false; } } catch (Exception e) { if (Fx.IsFatal(e)) { throw; } this.HandleError(e, request, channel); return false; } finally { if (releasePump) { this.ReleasePump(); } } return true; }
private void ReplyWithMetaData(RequestContext context) { var action = context.RequestMessage.Headers.Action; var contractInfo = ContractInfo.FromAction(action); var contractType = TypeFinder.FindServiceContract(contractInfo.ServiceContractName); var paramTypes = TypeFinder.GetContractParamTypes(contractType, contractInfo.OperationContractName, contractInfo.Action); var modelProvider = ObjectBuilder.GetModelProvider(); var typeMetaDatas = new Dictionary<string, string>(); var serializer = ObjectBuilder.GetSerializer(); foreach (var paramType in paramTypes) { if (typeMetaDatas.ContainsKey(paramType.Name)) continue; var modelInfo = modelProvider.CreateModelInfo(paramType.Type); var metaData = modelInfo.MetaData; var result = serializer.Serialize(metaData); var val = BinaryConverter.ToString(result.Data); typeMetaDatas.Add(paramType.Name, val); } var replyMessage = Message.CreateMessage(MessageVersion.Soap12WSAddressing10, context.RequestMessage.Headers.Action); foreach (var typeMetaData in typeMetaDatas) { replyMessage.Headers.Add(MessageHeader.CreateHeader(Constants.MetaDataHeaderKeySuffix + typeMetaData.Key, Constants.DefaultCustomHeaderNamespace, typeMetaData.Value)); } context.Reply(replyMessage); context.Close(); }
bool HandleErrorContinuation(Exception e, RequestContext request, ServiceChannel channel, ref ErrorHandlerFaultInfo faultInfo, bool replied) { if (replied) { try { request.Close(); } catch (Exception e1) { if (Fx.IsFatal(e1)) { throw; } this.HandleError(e1); } } else { request.Abort(); } if (!this.HandleError(e, ref faultInfo) && this.hasSession) { if (channel != null) { if (replied) { TimeoutHelper timeoutHelper = new TimeoutHelper(CloseAfterFaultTimeout); try { channel.Close(timeoutHelper.RemainingTime()); } catch (Exception e2) { if (Fx.IsFatal(e2)) { throw; } this.HandleError(e2); } try { this.binder.CloseAfterFault(timeoutHelper.RemainingTime()); } catch (Exception e3) { if (Fx.IsFatal(e3)) { throw; } this.HandleError(e3); } } else { channel.Abort(); this.binder.Abort(); } } else { if (replied) { try { this.binder.CloseAfterFault(CloseAfterFaultTimeout); } catch (Exception e4) { if (Fx.IsFatal(e4)) { throw; } this.HandleError(e4); } } else { this.binder.Abort(); } } } return true; }
private void EnsureChannelAndEndpoint(RequestContext request) { _requestInfo.Channel = _channel; if (_requestInfo.Channel == null) { bool addressMatched; if (_hasSession) { _requestInfo.Channel = this.GetSessionChannel(request.RequestMessage, out _requestInfo.Endpoint, out addressMatched); } else { _requestInfo.Channel = this.GetDatagramChannel(request.RequestMessage, out _requestInfo.Endpoint, out addressMatched); } if (_requestInfo.Channel == null) { if (addressMatched) { this.ReplyContractFilterDidNotMatch(request); } else { this.ReplyAddressFilterDidNotMatch(request); } } } else { _requestInfo.Endpoint = _requestInfo.Channel.EndpointDispatcher; } _requestInfo.EndpointLookupDone = true; if (_requestInfo.Channel == null) { // SFx drops a message here TraceUtility.TraceDroppedMessage(request.RequestMessage, _requestInfo.Endpoint); request.Close(); return; } if (_requestInfo.Channel.HasSession || _isCallback) { _requestInfo.DispatchRuntime = _requestInfo.Channel.DispatchRuntime; } else { _requestInfo.DispatchRuntime = _requestInfo.Endpoint.DispatchRuntime; } }
void DisposeRequestContext(RequestContext context) { try { context.Close(); ReceiveContextRPCFacet receiveContext = this.ReceiveContext; if (receiveContext != null) { this.ReceiveContext = null; IAsyncResult result = receiveContext.BeginComplete( TimeSpan.MaxValue, null, this.channelHandler, handleEndComplete, new CallbackState { ChannelHandler = this.channelHandler, ReceiveContext = receiveContext }); if (result.CompletedSynchronously) { receiveContext.EndComplete(result); } } } catch (Exception e) { if (Fx.IsFatal(e)) { throw; } this.AbortRequestContext(context); this.channelHandler.HandleError(e); } }
public bool ProcessInfo(WsrmMessageInfo info, RequestContext context, bool throwException) { Exception faultException; if (info.ParsingException != null) { WsrmFault fault; if (this.SequenceID != null) { string faultReason = System.ServiceModel.SR.GetString("CouldNotParseWithAction", new object[] { info.Action }); fault = SequenceTerminatedFault.CreateProtocolFault(this.SequenceID, faultReason, null); } else { fault = null; } faultException = new ProtocolException(System.ServiceModel.SR.GetString("MessageExceptionOccurred"), info.ParsingException); this.OnLocalFault(throwException ? null : faultException, fault, context); } else if (info.FaultReply != null) { faultException = info.FaultException; this.OnLocalFault(throwException ? null : faultException, info.FaultReply, context); } else if (((info.WsrmHeaderFault != null) && (info.WsrmHeaderFault.SequenceID != this.InputID)) && (info.WsrmHeaderFault.SequenceID != this.OutputID)) { faultException = new ProtocolException(System.ServiceModel.SR.GetString("WrongIdentifierFault", new object[] { FaultException.GetSafeReasonText(info.WsrmHeaderFault.Reason) })); this.OnLocalFault(throwException ? null : faultException, (Message) null, context); } else { if (info.FaultInfo == null) { return true; } if (this.isSessionClosed) { UnknownSequenceFault faultInfo = info.FaultInfo as UnknownSequenceFault; if (faultInfo != null) { UniqueId sequenceID = faultInfo.SequenceID; if (((this.OutputID != null) && (this.OutputID == sequenceID)) || ((this.InputID != null) && (this.InputID == sequenceID))) { if (this.settings.ReliableMessagingVersion == ReliableMessagingVersion.WSReliableMessagingFebruary2005) { info.Message.Close(); return false; } if (this.settings.ReliableMessagingVersion != ReliableMessagingVersion.WSReliableMessaging11) { throw Fx.AssertAndThrow("Unknown version."); } return true; } } } faultException = info.FaultException; if (context != null) { context.Close(); } this.OnRemoteFault(throwException ? null : faultException); } info.Message.Close(); if (throwException) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(faultException); } return false; }