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
- PnrpPermission.cs
- TextDecorationUnitValidation.cs
- EnumValAlphaComparer.cs
- DocumentCollection.cs
- EventHandlersStore.cs
- Deflater.cs
- XmlSchemaAll.cs
- ListControl.cs
- PartDesigner.cs
- IntellisenseTextBox.cs
- StylusPointPropertyUnit.cs
- ColumnResult.cs
- GeometryDrawing.cs
- FlowDocumentPage.cs
- PerfService.cs
- UnmanagedMemoryStream.cs
- StylusPointPropertyInfoDefaults.cs
- AnnotationService.cs
- Vector3dCollection.cs
- NumberFormatter.cs
- ChineseLunisolarCalendar.cs
- ClipboardData.cs
- Debug.cs
- BindingCollection.cs
- OleDbReferenceCollection.cs
- TcpProcessProtocolHandler.cs
- StrongName.cs
- SelectionRange.cs
- RowToFieldTransformer.cs
- XmlAutoDetectWriter.cs
- EllipseGeometry.cs
- ConfigurationValidatorAttribute.cs
- XmlBinaryReaderSession.cs
- WrappedReader.cs
- XmlAttributeCache.cs
- AstNode.cs
- XmlImplementation.cs
- Size3D.cs
- Exceptions.cs
- SetIterators.cs
- ContextMenu.cs
- SelectionPatternIdentifiers.cs
- CalendarDateRangeChangingEventArgs.cs
- WebControlAdapter.cs
- SecurityTokenException.cs
- Vector3DIndependentAnimationStorage.cs
- AppDomainProtocolHandler.cs
- DbParameterCollection.cs
- TableRowCollection.cs
- Point3D.cs
- util.cs
- DataGridViewRowContextMenuStripNeededEventArgs.cs
- DBSchemaTable.cs
- PriorityBindingExpression.cs
- ListControlBoundActionList.cs
- DATA_BLOB.cs
- MimeFormatExtensions.cs
- JsonServiceDocumentSerializer.cs
- PropertyEntry.cs
- DataSourceSelectArguments.cs
- DataTableReader.cs
- LayoutEngine.cs
- TableLayoutRowStyleCollection.cs
- ConfigurationSectionHelper.cs
- DataMisalignedException.cs
- _NestedSingleAsyncResult.cs
- VectorKeyFrameCollection.cs
- LayoutManager.cs
- FileSystemInfo.cs
- WorkflowDefinitionDispenser.cs
- ProviderSettingsCollection.cs
- SimpleParser.cs
- Simplifier.cs
- PersonalizationProviderCollection.cs
- DataGridView.cs
- DataGridViewComboBoxCell.cs
- QueryStringParameter.cs
- LazyTextWriterCreator.cs
- WebPartUserCapability.cs
- MailMessage.cs
- ContextToken.cs
- PassportIdentity.cs
- InputBuffer.cs
- TransformPattern.cs
- SemanticTag.cs
- OpCodes.cs
- ResourcesChangeInfo.cs
- StructuredTypeEmitter.cs
- ActivityXRefPropertyEditor.cs
- DoubleAnimationBase.cs
- WorkflowServiceAttributes.cs
- CounterCreationData.cs
- MouseCaptureWithinProperty.cs
- GroupBoxDesigner.cs
- FullTextLine.cs
- AbstractExpressions.cs
- UrlRoutingModule.cs
- RoutedCommand.cs
- BitmapCodecInfo.cs
- HtmlInputButton.cs