public async Task DispatchAsync(Message message) { if (message == null) //0 bytes { //We have already closed all channels, return. (Couldn't use DoneReceivingInCurrentState()) if (_channel.State == CommunicationState.Closed || _channel.State == CommunicationState.Closing || _channel.State == CommunicationState.Closed) { return; } else { await _serviceChannelDispatcher.DispatchAsync(message); return; } } IServiceDispatcher serviceDispatcher = _demuxer.MatchDispatcher(message); if (serviceDispatcher == null) { ErrorBehavior.ThrowAndCatch( new EndpointNotFoundException(SR.Format(SR.UnableToDemuxChannel, message.Headers.Action)), message); await _demuxer.EndpointNotFoundAsync((IDuplexSessionChannel)_channel, message); return; } _serviceChannelDispatcher = await serviceDispatcher.CreateServiceChannelDispatcherAsync(_channel); await _serviceChannelDispatcher.DispatchAsync(message); }
public async Task DispatchAsync(RequestContext context) { // TODO: Find way to avoid instantiating a new ServiceChannelDispatcher each time IServiceDispatcher serviceDispatcher = _demuxer.MatchDispatcher(context.RequestMessage); if (serviceDispatcher == null) { ErrorBehavior.ThrowAndCatch( new EndpointNotFoundException(SR.Format(SR.UnableToDemuxChannel, context.RequestMessage.Headers.Action)), context.RequestMessage); } // TODO: if serviceDispatcher == null, use the EndpointNotFound code path IServiceChannelDispatcher serviceChannelDispatcher = await serviceDispatcher.CreateServiceChannelDispatcherAsync(_channel); await serviceChannelDispatcher.DispatchAsync(context); }
private bool IsImpersonatedContext() { SafeCloseHandle tokenHandle = null; if (!System.ServiceModel.ComIntegration.SafeNativeMethods.OpenCurrentThreadToken(System.ServiceModel.ComIntegration.SafeNativeMethods.GetCurrentThread(), TokenAccessLevels.Query, true, out tokenHandle)) { int error = Marshal.GetLastWin32Error(); Utility.CloseInvalidOutSafeHandle(tokenHandle); if (error == 0x3f0) { return(false); } ErrorBehavior.ThrowAndCatch(new Win32Exception(error)); return(true); } tokenHandle.Close(); return(true); }
private bool ProcessItem(TInnerItem item) { bool flag; try { Message message = this.GetMessage(item); IChannelListener listener = null; try { listener = this.MatchListener(message); } catch (CommunicationException exception) { if (DiagnosticUtility.ShouldTraceInformation) { DiagnosticUtility.ExceptionUtility.TraceHandledException(exception, TraceEventType.Information); } return(false); } catch (MultipleFilterMatchesException exception2) { if (DiagnosticUtility.ShouldTraceInformation) { DiagnosticUtility.ExceptionUtility.TraceHandledException(exception2, TraceEventType.Information); } return(false); } catch (XmlException exception3) { if (DiagnosticUtility.ShouldTraceInformation) { DiagnosticUtility.ExceptionUtility.TraceHandledException(exception3, TraceEventType.Information); } return(false); } catch (Exception exception4) { if (Fx.IsFatal(exception4)) { throw; } this.HandleUnknownException(exception4); return(true); } if (listener == null) { ErrorBehavior.ThrowAndCatch(new EndpointNotFoundException(System.ServiceModel.SR.GetString("UnableToDemuxChannel", new object[] { message.Headers.Action })), message); this.EndpointNotFound(item); item = default(TInnerItem); return(false); } if (this.onItemDequeued == null) { this.onItemDequeued = new Action(this.OnItemDequeued); } this.EnqueueAndDispatch(listener, item, this.onItemDequeued, false); item = default(TInnerItem); flag = true; } finally { if (item != null) { this.AbortItem(item); } } return(flag); }
private void OnConnectionModeKnownCore(ConnectionModeReader modeReader, bool isCached) { lock (this.ThisLock) { if (this.isDisposed) { return; } this.connectionReaders.Remove(modeReader); } bool flag = true; try { FramingMode connectionMode; try { connectionMode = modeReader.GetConnectionMode(); } catch (CommunicationException exception) { TraceEventType exceptionEventType = modeReader.Connection.ExceptionEventType; if (DiagnosticUtility.ShouldTrace(exceptionEventType)) { DiagnosticUtility.ExceptionUtility.TraceHandledException(exception, exceptionEventType); } return; } catch (TimeoutException exception2) { if (!isCached) { exception2 = new TimeoutException(System.ServiceModel.SR.GetString("ChannelInitializationTimeout", new object[] { this.channelInitializationTimeout }), exception2); ErrorBehavior.ThrowAndCatch(exception2); } TraceEventType type = modeReader.Connection.ExceptionEventType; if (DiagnosticUtility.ShouldTrace(type)) { DiagnosticUtility.ExceptionUtility.TraceHandledException(exception2, type); } return; } switch (connectionMode) { case FramingMode.Singleton: this.OnSingletonConnection(modeReader.Connection, modeReader.ConnectionDequeuedCallback, modeReader.StreamPosition, modeReader.BufferOffset, modeReader.BufferSize, modeReader.GetRemainingTimeout()); break; case FramingMode.Duplex: this.OnDuplexConnection(modeReader.Connection, modeReader.ConnectionDequeuedCallback, modeReader.StreamPosition, modeReader.BufferOffset, modeReader.BufferSize, modeReader.GetRemainingTimeout()); break; default: { Exception innerException = new InvalidDataException(System.ServiceModel.SR.GetString("FramingModeNotSupported", new object[] { connectionMode })); Exception exception4 = new ProtocolException(innerException.Message, innerException); FramingEncodingString.AddFaultString(exception4, "http://schemas.microsoft.com/ws/2006/05/framing/faults/UnsupportedMode"); ErrorBehavior.ThrowAndCatch(exception4); return; } } flag = false; } catch (Exception exception5) { if (Fx.IsFatal(exception5)) { throw; } if (!System.ServiceModel.Dispatcher.ExceptionHandler.HandleTransportExceptionHelper(exception5)) { throw; } } finally { if (flag) { modeReader.Dispose(); } } }