public void AddBindingParameters(ServiceEndpoint endpoint, BindingParameterCollection bindingParameters) { //Turn on ReceiveContext here if supported IReceiveContextSettings receiveContextSettings = endpoint.Binding.GetProperty <IReceiveContextSettings>(bindingParameters); if (receiveContextSettings != null) { receiveContextSettings.Enabled = true; } }
public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher) { this.ChannelDispatcher = endpointDispatcher.ChannelDispatcher; this.ChannelDispatcher.ChannelInitializers.Add(this); endpointDispatcher.DispatchRuntime.InputSessionShutdownHandlers.Add(this); endpointDispatcher.DispatchRuntime.AutomaticInputSessionShutdown = false; if (endpointDispatcher.DispatchRuntime.ImpersonateCallerForAllOperations) { this.ImpersonationRequired = true; } else if (AspNetEnvironment.Current.AspNetCompatibilityEnabled) { this.ImpersonationRequired = true; } BindingParameterCollection bindingParams = new BindingParameterCollection(); if (RoutingUtilities.IsTransactedReceive(endpoint.Binding, bindingParams)) { foreach (OperationDescription operation in endpoint.Contract.Operations) { if (operation.Behaviors.Find <TransactedReceiveOperationBehavior>() == null) { operation.Behaviors.Add(new TransactedReceiveOperationBehavior()); } } this.ChannelDispatcher.IsTransactedReceive = true; endpointDispatcher.DispatchRuntime.TransactionAutoCompleteOnSessionClose = true; this.TransactedReceiveEnabled = true; } IReceiveContextSettings rcSettings = endpoint.Binding.GetProperty <IReceiveContextSettings>(bindingParams); if (rcSettings != null && rcSettings.Enabled) { foreach (OperationDescription operation in endpoint.Contract.Operations) { ReceiveContextEnabledAttribute rcEnabled = new ReceiveContextEnabledAttribute(); rcEnabled.ManualControl = true; operation.Behaviors.Add(rcEnabled); } this.ReceiveContextEnabled = true; //Switch TransactedReceive off, because we don't want the Dispatcher creating any Transaction endpointDispatcher.ChannelDispatcher.IsTransactedReceive = false; endpointDispatcher.DispatchRuntime.TransactionAutoCompleteOnSessionClose = false; } }
public MsmqReceiveContextSettings(IReceiveContextSettings toBeCloned) { Enabled = toBeCloned.Enabled; ValidityDuration = toBeCloned.ValidityDuration; }
private ChannelDispatcher CreateChannelDispatcher(ServiceEndpoint endpoint, Type serviceType, Dictionary <string, string> actionMap) { EndpointAddress address = endpoint.Address; Binding binding = endpoint.Binding; BindingParameterCollection bindingParameters = new BindingParameterCollection(); ((IEndpointBehavior) new TransportClientEndpointBehavior(tokenProvider)).AddBindingParameters(endpoint, bindingParameters); if (receiveMode == ReceiveMode.PeekLock) { IReceiveContextSettings receiveContextSettings = binding.GetProperty <IReceiveContextSettings>(bindingParameters); Debug.Assert(receiveContextSettings != null); receiveContextSettings.Enabled = true; } IChannelListener channelListener; if (endpoint.Contract.SessionMode == SessionMode.Required) { channelListener = binding.BuildChannelListener <IInputSessionChannel>(address.Uri, bindingParameters); } else { channelListener = binding.BuildChannelListener <IInputChannel>(address.Uri, bindingParameters); } ChannelDispatcher channelDispatcher = new ChannelDispatcher(channelListener, binding.Namespace + ":" + binding.Name, binding); channelDispatcher.MessageVersion = binding.MessageVersion; EndpointDispatcher endpointDispatcher = new EndpointDispatcher(address, endpoint.Contract.Name, endpoint.Contract.Namespace, false); endpointDispatcher.DispatchRuntime.Type = serviceType; endpointDispatcher.AddressFilter = new EndpointAddressMessageFilter(endpoint.Address); endpointDispatcher.ContractFilter = new MatchAllMessageFilter(); endpointDispatcher.FilterPriority = 0; endpointDispatcher.DispatchRuntime.OperationSelector = new BrokeredOperationSelector(actionMap); foreach (OperationDescription operation in endpoint.Contract.Operations) { DispatchOperation operationDispatcher = new DispatchOperation(endpointDispatcher.DispatchRuntime, operation.Name, string.Empty); operationDispatcher.Formatter = new BrokeredFormatter(); Debug.Assert(operation.SyncMethod != null); if (operation.SyncMethod.ReturnType == typeof(void)) { operationDispatcher.Invoker = new SyncOperationInvoker(operation.SyncMethod); } else { Debug.Assert(operation.SyncMethod.ReturnType == typeof(Task)); operationDispatcher.Invoker = new TaskMethodInvoker(operation.SyncMethod); } foreach (IOperationBehavior operationBehavior in operation.Behaviors) { operationBehavior.ApplyDispatchBehavior(operation, operationDispatcher); } endpointDispatcher.DispatchRuntime.Operations.Add(operationDispatcher); } channelDispatcher.ReceiveContextEnabled = (receiveMode == ReceiveMode.PeekLock); SetErrorHandler(channelDispatcher, serviceType); channelDispatcher.Endpoints.Add(endpointDispatcher); return(channelDispatcher); }