private async Task DispatchAndReleasePumpAsync(RequestContext request, bool cleanThread, RequestInfo requestInfo) { OperationContext currentOperationContext = null; ServiceChannel channel = requestInfo.Channel; EndpointDispatcher endpoint = requestInfo.Endpoint; bool releasedPump = false; try { DispatchRuntime dispatchBehavior = requestInfo.DispatchRuntime; if (channel == null || dispatchBehavior == null) { Fx.Assert("System.ServiceModel.Dispatcher.ChannelHandler.Dispatch(): (channel == null || dispatchBehavior == null)"); return; } Message message; //EventTraceActivity eventTraceActivity = TraceDispatchMessageStart(request.RequestMessage); message = request.RequestMessage; DispatchOperationRuntime operation = dispatchBehavior.GetOperation(ref message); if (operation == null) { Fx.Assert("ChannelHandler.Dispatch (operation == null)"); throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "No DispatchOperationRuntime found to process message."))); } if (_shouldRejectMessageWithOnOpenActionHeader && message.Headers.Action == OperationDescription.SessionOpenedAction) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.SFxNoEndpointMatchingAddressForConnectionOpeningMessage, message.Headers.Action, "Open"))); } //if (MessageLogger.LoggingEnabled) //{ // MessageLogger.LogMessage(ref message, (operation.IsOneWay ? MessageLoggingSource.ServiceLevelReceiveDatagram : MessageLoggingSource.ServiceLevelReceiveRequest) | MessageLoggingSource.LastChance); //} if (operation.IsTerminating && _hasSession) { _isChannelTerminated = true; } bool hasOperationContextBeenSet; if (currentOperationContext != null) { hasOperationContextBeenSet = true; currentOperationContext.ReInit(request, message, channel); } else { hasOperationContextBeenSet = false; currentOperationContext = new OperationContext(request, message, channel, _host); } if (currentOperationContext.EndpointDispatcher == null && _serviceDispatcher != null) { currentOperationContext.EndpointDispatcher = endpoint; } var rpc = new MessageRpc(request, message, operation, channel, _host, this, cleanThread, currentOperationContext, requestInfo.ExistingInstanceContext); //TraceUtility.MessageFlowAtMessageReceived(message, currentOperationContext, eventTraceActivity, true); // passing responsibility for call throttle to MessageRpc // (MessageRpc implicitly owns this throttle once it's created) requestInfo.ChannelHandlerOwnsCallThrottle = false; // explicitly passing responsibility for instance throttle to MessageRpc rpc.MessageRpcOwnsInstanceContextThrottle = requestInfo.ChannelHandlerOwnsInstanceContextThrottle; requestInfo.ChannelHandlerOwnsInstanceContextThrottle = false; // These need to happen before Dispatch but after accessing any ChannelHandler // state, because we go multi-threaded after this ReleasePump(); releasedPump = true; await operation.Parent.DispatchAsync(rpc, hasOperationContextBeenSet); } catch (Exception e) { if (Fx.IsFatal(e)) { throw; } await HandleErrorAsync(e, request, requestInfo, channel); } finally { if (!releasedPump) { ReleasePump(); } } }
//bool didTraceProcessMessage1 = false; //bool didTraceProcessMessage2 = false; //bool didTraceProcessMessage3 = false; //bool didTraceProcessMessage31 = false; //bool didTraceProcessMessage4 = false; //bool didTraceProcessMessage41 = false; internal ImmutableDispatchRuntime(DispatchRuntime dispatch) { //this.authenticationBehavior = AuthenticationBehavior.TryCreate(dispatch); //this.authorizationBehavior = AuthorizationBehavior.TryCreate(dispatch); concurrency = new ConcurrencyBehavior(dispatch); error = new ErrorBehavior(dispatch.ChannelDispatcher); enableFaults = dispatch.EnableFaults; inputSessionShutdownHandlers = EmptyArray <IInputSessionShutdown> .ToArray(dispatch.InputSessionShutdownHandlers); instance = new InstanceBehavior(dispatch, this); isOnServer = dispatch.IsOnServer; manualAddressing = dispatch.ManualAddressing; messageInspectors = EmptyArray <IDispatchMessageInspector> .ToArray(dispatch.MessageInspectors); //this.requestReplyCorrelator = new RequestReplyCorrelator(); //this.securityImpersonation = SecurityImpersonationBehavior.CreateIfNecessary(dispatch); //this.RequireClaimsPrincipalOnOperationContext = dispatch.RequireClaimsPrincipalOnOperationContext; //this.impersonateOnSerializingReply = dispatch.ImpersonateOnSerializingReply; terminate = TerminatingOperationBehavior.CreateIfNecessary(dispatch); thread = new ThreadBehavior(dispatch); ValidateMustUnderstand = dispatch.ValidateMustUnderstand; //this.ignoreTransactionFlow = dispatch.IgnoreTransactionMessageProperty; //this.transaction = TransactionBehavior.CreateIfNeeded(dispatch); //sendAsynchronously = dispatch.ChannelDispatcher.SendAsynchronously; ParameterInspectorCorrelationOffset = (dispatch.MessageInspectors.Count + dispatch.MaxCallContextInitializers); correlationCount = ParameterInspectorCorrelationOffset + dispatch.MaxParameterInspectors; DispatchOperationRuntime unhandled = new DispatchOperationRuntime(dispatch.UnhandledDispatchOperation, this); if (dispatch.OperationSelector == null) { ActionDemuxer demuxer = new ActionDemuxer(); for (int i = 0; i < dispatch.Operations.Count; i++) { DispatchOperation operation = dispatch.Operations[i]; DispatchOperationRuntime operationRuntime = new DispatchOperationRuntime(operation, this); demuxer.Add(operation.Action, operationRuntime); } demuxer.SetUnhandled(unhandled); this.demuxer = demuxer; } else { throw new PlatformNotSupportedException(); // CustomDemuxer demuxer = new CustomDemuxer(dispatch.OperationSelector); // for (int i = 0; i < dispatch.Operations.Count; i++) // { // DispatchOperation operation = dispatch.Operations[i]; // DispatchOperationRuntime operationRuntime = new DispatchOperationRuntime(operation, this); // demuxer.Add(operation.Name, operationRuntime); // } // demuxer.SetUnhandled(unhandled); // this.demuxer = demuxer; } //processMessage1 = new MessageRpcProcessor(ProcessMessage1); //processMessage11 = new MessageRpcProcessor(ProcessMessage11); //processMessage2 = new MessageRpcProcessor(ProcessMessage2); //processMessage3 = new MessageRpcProcessor(ProcessMessage3); //processMessage31 = new MessageRpcProcessor(ProcessMessage31); //processMessage4 = new MessageRpcProcessor(ProcessMessage4); //processMessage41 = new MessageRpcProcessor(ProcessMessage41); //processMessage5 = new MessageRpcProcessor(ProcessMessage5); //processMessage6 = new MessageRpcProcessor(ProcessMessage6); //processMessage7 = new MessageRpcProcessor(ProcessMessage7); //processMessage8 = new MessageRpcProcessor(ProcessMessage8); //processMessage9 = new MessageRpcProcessor(ProcessMessage9); //processMessageCleanup = new MessageRpcProcessor(ProcessMessageCleanup); processMessageNonCleanupError = new MessageRpcErrorHandler(ProcessMessageNonCleanupError); processMessageCleanupError = new MessageRpcErrorHandler(ProcessMessageCleanupError); }
internal ThreadBehavior(DispatchRuntime dispatch) { context = dispatch.SynchronizationContext; }
internal ConcurrencyBehavior(DispatchRuntime runtime) { concurrencyMode = runtime.ConcurrencyMode; enforceOrderedReceive = runtime.EnsureOrderedDispatch; //this.supportsTransactedBatch = ConcurrencyBehavior.SupportsTransactedBatch(runtime.ChannelDispatcher); }
internal PerSessionInstanceContextProvider(DispatchRuntime dispatchRuntime) : base(dispatchRuntime) { }
internal PerCallInstanceContextProvider(DispatchRuntime dispatchRuntime) : base(dispatchRuntime) { }
internal SingletonInstanceContextProvider(DispatchRuntime dispatchRuntime) : base(dispatchRuntime) { thisLock = new object(); }
// Similar to DispatchAndReleasePump on Desktop internal async Task DispatchAsyncCore(RequestContext request, RequestInfo requestInfo, bool cleanThread, OperationContext currentOperationContext) { ServiceChannel channel = requestInfo.Channel; EndpointDispatcher endpoint = requestInfo.Endpoint; try { DispatchRuntime dispatchBehavior = requestInfo.DispatchRuntime; if (channel == null || dispatchBehavior == null) { Fx.Assert("System.ServiceModel.Dispatcher.ChannelHandler.Dispatch(): (channel == null || dispatchBehavior == null)"); } Message message = request.RequestMessage; DispatchOperationRuntime operation = dispatchBehavior.GetOperation(ref message); if (operation == null) { Fx.Assert("ChannelHandler.Dispatch (operation == null)"); throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException("No DispatchOperationRuntime found to process message.")); } if (_shouldRejectMessageWithOnOpenActionHeader && message.Headers.Action == OperationDescription.SessionOpenedAction) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.SFxNoEndpointMatchingAddressForConnectionOpeningMessage, message.Headers.Action, "Open"))); } if (operation.IsTerminating && _hasSession) { _isChannelTerminated = true; } bool hasOperationContextBeenSet; if (currentOperationContext != null) { hasOperationContextBeenSet = true; currentOperationContext.ReInit(request, message, channel); } else { hasOperationContextBeenSet = false; currentOperationContext = new OperationContext(request, message, channel, null); } if (currentOperationContext.EndpointDispatcher == null && _serviceDispatcher != null) { currentOperationContext.EndpointDispatcher = endpoint; } MessageRpc rpc = new MessageRpc(request, message, operation, channel, _host, this, cleanThread, currentOperationContext, requestInfo.ExistingInstanceContext); // passing responsibility for call throttle to MessageRpc // (MessageRpc implicitly owns this throttle once it's created) requestInfo.ChannelHandlerOwnsCallThrottle = false; // explicitly passing responsibility for instance throttle to MessageRpc rpc.MessageRpcOwnsInstanceContextThrottle = requestInfo.ChannelHandlerOwnsInstanceContextThrottle; requestInfo.ChannelHandlerOwnsInstanceContextThrottle = false; // These need to happen before Dispatch but after accessing any ChannelHandler // state, because we go multi-threaded after this until we reacquire pump mutex. await operation.Parent.DispatchAsync(rpc, hasOperationContextBeenSet); } catch (Exception e) { if (Fx.IsFatal(e)) { throw; } await HandleErrorAsync(e, request, requestInfo, channel); } }
internal DispatchOperation(DispatchRuntime parent, string name, string action, string replyAction) : this(parent, name, action) { this.replyAction = replyAction; IsOneWay = false; }
internal DispatchBehaviorCollection(DispatchRuntime outer) : base(outer.ThisLock) { this.outer = outer; }
internal OperationCollection(DispatchRuntime outer) : base(outer.ThisLock) { this.outer = outer; }
public UnhandledActionInvoker(DispatchRuntime dispatchRuntime) { this.dispatchRuntime = dispatchRuntime; }
void IContractBehavior.ApplyDispatchBehavior(ContractDescription description, ServiceEndpoint endpoint, DispatchRuntime dispatch) { if (dispatch.ClientRuntime != null) { dispatch.ClientRuntime.OperationSelector = new MethodInfoOperationSelector(description, MessageDirection.Output); } }
internal static IInstanceContextProvider GetProviderForMode(InstanceContextMode instanceMode, DispatchRuntime runtime) { switch (instanceMode) { case InstanceContextMode.PerCall: return(new PerCallInstanceContextProvider(runtime)); case InstanceContextMode.PerSession: return(new PerSessionInstanceContextProvider(runtime)); case InstanceContextMode.Single: return(new SingletonInstanceContextProvider(runtime)); default: DiagnosticUtility.FailFast("InstanceContextProviderBase.GetProviderForMode: default"); return(null); } }
internal InstanceContextProviderBase(DispatchRuntime dispatchRuntime) { DispatchRuntime = dispatchRuntime; }
private static AuthenticationBehavior CreateAuthenticationBehavior(DispatchRuntime dispatch) { AuthenticationBehavior authenticationBehavior = new AuthenticationBehavior(dispatch.ServiceAuthenticationManager); return(authenticationBehavior); }