Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / System.ServiceModel.Routing / System / ServiceModel / Routing / RoutingBehavior.cs / 1305376 / RoutingBehavior.cs
//---------------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. //--------------------------------------------------------------- namespace System.ServiceModel.Routing { using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Runtime; using System.ServiceModel; using System.ServiceModel.Activation; using System.ServiceModel.Channels; using System.ServiceModel.Description; using System.ServiceModel.Dispatcher; [Fx.Tag.XamlVisible(false)] public sealed class RoutingBehavior : IServiceBehavior { RoutingConfiguration configuration; public RoutingBehavior(RoutingConfiguration routingConfiguration) { if (routingConfiguration == null) { throw FxTrace.Exception.ArgumentNull("routingConfiguration"); } this.configuration = routingConfiguration; } void IServiceBehavior.AddBindingParameters(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase, Collectionendpoints, BindingParameterCollection bindingParameters) { } void IServiceBehavior.ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase) { RoutingExtension routingExtension = new RoutingExtension(this.configuration); serviceHostBase.Extensions.Add(routingExtension); for (int i = 0; i < serviceHostBase.ChannelDispatchers.Count; i++) { ChannelDispatcher channelDispatcher = serviceHostBase.ChannelDispatchers[i] as ChannelDispatcher; if (channelDispatcher != null) { foreach (EndpointDispatcher endpointDispatcher in channelDispatcher.Endpoints) { if (!endpointDispatcher.IsSystemEndpoint && RoutingUtilities.IsRoutingServiceNamespace(endpointDispatcher.ContractNamespace)) { DispatchRuntime dispatchRuntime = endpointDispatcher.DispatchRuntime; //Since we use PerSession instancing this concurrency only applies to messages //in the same session, also needed to maintain order. dispatchRuntime.ConcurrencyMode = ConcurrencyMode.Single; } } } } } void IServiceBehavior.Validate(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase) { HashSet endpoints = new HashSet (); foreach (ServiceEndpoint endpoint in serviceDescription.Endpoints) { if (!endpoint.IsSystemEndpoint && RoutingUtilities.IsRoutingServiceNamespace(endpoint.Contract.Namespace)) { endpoint.Behaviors.Add(new RoutingEndpointBehavior(endpoint)); endpoints.Add(endpoint.Name); } } EndpointNameMessageFilter.Validate(this.configuration.InternalFilterTable.Keys, endpoints); } public static Type GetContractForDescription(ContractDescription description) { if (description == null) { throw FxTrace.Exception.ArgumentNull("description"); } if (description.CallbackContractType != null) { return typeof(IDuplexSessionRouter); } bool allOneWay = true; foreach (OperationDescription operation in description.Operations) { if (!operation.IsOneWay) { allOneWay = false; break; } } if (allOneWay) { if (description.SessionMode == SessionMode.Required) { return typeof(ISimplexSessionRouter); } else { return typeof(ISimplexDatagramRouter); } } else { return typeof(IRequestReplyRouter); } } internal class RoutingEndpointBehavior : IEndpointBehavior, IChannelInitializer, IInputSessionShutdown { public RoutingEndpointBehavior(ServiceEndpoint endpoint) { this.Endpoint = endpoint; this.EndpointName = endpoint.Name; } internal ChannelDispatcher ChannelDispatcher { get; private set; } internal ServiceEndpoint Endpoint { get; private set; } internal string EndpointName { get; private set; } internal bool ImpersonationRequired { get; private set; } internal bool ReceiveContextEnabled { get; private set; } internal bool TransactedReceiveEnabled { get; private set; } public void AddBindingParameters(ServiceEndpoint endpoint, BindingParameterCollection bindingParameters) { //Turn on ReceiveContext here if supported IReceiveContextSettings receiveContextSettings = endpoint.Binding.GetProperty (bindingParameters); if (receiveContextSettings != null) { receiveContextSettings.Enabled = true; } } public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime) { } 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 () == null) { operation.Behaviors.Add(new TransactedReceiveOperationBehavior()); } } this.ChannelDispatcher.IsTransactedReceive = true; endpointDispatcher.DispatchRuntime.TransactionAutoCompleteOnSessionClose = true; this.TransactedReceiveEnabled = true; } IReceiveContextSettings rcSettings = endpoint.Binding.GetProperty (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 void Validate(ServiceEndpoint endpoint) { } void IChannelInitializer.Initialize(IClientChannel channel) { RoutingChannelExtension channelState = RoutingChannelExtension.Create(this); channel.Extensions.Add(channelState); } void IInputSessionShutdown.ChannelFaulted(IDuplexContextChannel channel) { RoutingChannelExtension channelExtension = channel.Extensions.Find (); if (channelExtension != null) { channelExtension.Fault(new CommunicationObjectFaultedException()); } else { RoutingUtilities.Abort(channel, channel.LocalAddress); } } void IInputSessionShutdown.DoneReceiving(IDuplexContextChannel channel) { RoutingChannelExtension channelExtension = channel.Extensions.Find (); channelExtension.DoneReceiving(this.Endpoint.Binding.CloseTimeout); } } class TransactedReceiveOperationBehavior : IOperationBehavior { public void AddBindingParameters(OperationDescription operationDescription, BindingParameterCollection bindingParameters) { } public void ApplyClientBehavior(OperationDescription operationDescription, ClientOperation clientOperation) { } public void ApplyDispatchBehavior(OperationDescription operationDescription, DispatchOperation dispatchOperation) { if (operationDescription.Behaviors.Find () == null) { dispatchOperation.TransactionRequired = true; } ContractDescription contract = operationDescription.DeclaringContract; if (dispatchOperation.IsOneWay && contract.SessionMode == SessionMode.Required) { dispatchOperation.Parent.ConcurrencyMode = ConcurrencyMode.Single; dispatchOperation.Parent.ReleaseServiceInstanceOnTransactionComplete = false; dispatchOperation.TransactionAutoComplete = false; } } public void Validate(OperationDescription operationDescription) { } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- SqlDataSource.cs
- ChannelManagerHelpers.cs
- GroupByQueryOperator.cs
- PrintControllerWithStatusDialog.cs
- SvcMapFileLoader.cs
- DBSqlParserTable.cs
- SelectedPathEditor.cs
- RenderContext.cs
- ArrayListCollectionBase.cs
- HttpApplicationFactory.cs
- AudioSignalProblemOccurredEventArgs.cs
- glyphs.cs
- ToolStripDropDownClosingEventArgs.cs
- HtmlInputControl.cs
- Asn1IntegerConverter.cs
- CuspData.cs
- WmpBitmapEncoder.cs
- Brush.cs
- TextTreeTextBlock.cs
- DockingAttribute.cs
- SharedUtils.cs
- SharedUtils.cs
- AbstractDataSvcMapFileLoader.cs
- ClientScriptManagerWrapper.cs
- ConnectionPoint.cs
- Random.cs
- BuiltInExpr.cs
- AuthenticationSection.cs
- SqlUtil.cs
- StatusBarAutomationPeer.cs
- ContainerVisual.cs
- TextAdaptor.cs
- DrawingContextWalker.cs
- RichTextBox.cs
- WindowCollection.cs
- BulletDecorator.cs
- OutOfProcStateClientManager.cs
- WindowsGraphics.cs
- XsltArgumentList.cs
- Transform3DGroup.cs
- CorrelationQueryBehavior.cs
- AuthenticatingEventArgs.cs
- Utils.cs
- TrustManagerMoreInformation.cs
- CanonicalFormWriter.cs
- ColorInterpolationModeValidation.cs
- CryptoProvider.cs
- ExpressionNormalizer.cs
- DataGridViewCellToolTipTextNeededEventArgs.cs
- SqlNodeAnnotation.cs
- QueryExtender.cs
- DerivedKeyCachingSecurityTokenSerializer.cs
- LinearGradientBrush.cs
- StatementContext.cs
- BitmapInitialize.cs
- SourceInterpreter.cs
- EndOfStreamException.cs
- ExtentCqlBlock.cs
- AttachedPropertyBrowsableForTypeAttribute.cs
- TransformerConfigurationWizardBase.cs
- PlaceHolder.cs
- StorageMappingFragment.cs
- WebPartRestoreVerb.cs
- DataSourceControlBuilder.cs
- CharacterBufferReference.cs
- AssemblyBuilder.cs
- BaseAddressPrefixFilterElementCollection.cs
- ReturnEventArgs.cs
- XmlLanguageConverter.cs
- ConfigurationManagerHelper.cs
- HttpWebResponse.cs
- SymbolType.cs
- SqlDataSourceFilteringEventArgs.cs
- JobPageOrder.cs
- OrderByQueryOptionExpression.cs
- Listbox.cs
- DependencyProperty.cs
- ValueChangedEventManager.cs
- SafeCoTaskMem.cs
- WebPartTransformerCollection.cs
- Shape.cs
- Activity.cs
- JsonFormatMapping.cs
- Pair.cs
- FontDifferentiator.cs
- JoinTreeSlot.cs
- WpfPayload.cs
- TimeoutException.cs
- UInt16Converter.cs
- EllipseGeometry.cs
- StructuredCompositeActivityDesigner.cs
- SessionStateContainer.cs
- SqlInfoMessageEvent.cs
- XmlElementAttribute.cs
- ToolStripSystemRenderer.cs
- HttpFormatExtensions.cs
- SoapCodeExporter.cs
- PersistenceTypeAttribute.cs
- UnSafeCharBuffer.cs
- XmlSchemaChoice.cs