Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Channels / TransactionChannelFactory.cs / 1 / TransactionChannelFactory.cs
//---------------------------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. //--------------------------------------------------------------------------- namespace System.ServiceModel.Channels { using System.ServiceModel; using System.ServiceModel.Description; using System.Collections.Generic; using System.Transactions; using System.ServiceModel.Transactions; using System.ServiceModel.Security; using SR=System.ServiceModel.SR; sealed class TransactionChannelFactory: LayeredChannelFactory , ITransactionChannelManager { TransactionFlowOption flowIssuedTokens; SecurityStandardsManager standardsManager; Dictionary dictionary; TransactionProtocol transactionProtocol; public TransactionChannelFactory( TransactionProtocol transactionProtocol, BindingContext context, Dictionary dictionary) : base(context.Binding, context.BuildInnerChannelFactory ()) { this.dictionary = dictionary; this.TransactionProtocol = transactionProtocol; this.standardsManager = SecurityStandardsHelper.CreateStandardsManager(this.TransactionProtocol); } public TransactionProtocol TransactionProtocol { get { return this.transactionProtocol; } set { if (!TransactionProtocol.IsDefined(value)) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError( new ArgumentException(SR.GetString(SR.SFxBadTransactionProtocols))); this.transactionProtocol = value; } } public TransactionFlowOption FlowIssuedTokens { get { return this.flowIssuedTokens; } set { this.flowIssuedTokens = value; } } public SecurityStandardsManager StandardsManager { get { return this.standardsManager; } set { this.standardsManager = (value != null ? value : SecurityStandardsHelper.CreateStandardsManager(this.transactionProtocol)); } } public IDictionary Dictionary { get { return this.dictionary; } } public TransactionFlowOption GetTransaction(MessageDirection direction, string action) { TransactionFlowOption txOption; if (!dictionary.TryGetValue(new DirectionalAction(direction, action), out txOption)) return TransactionFlowOption.NotAllowed; else return txOption; } protected override TChannel OnCreateChannel(EndpointAddress remoteAddress, Uri via) { TChannel innerChannel = ((IChannelFactory )InnerChannelFactory).CreateChannel(remoteAddress, via); return CreateTransactionChannel(innerChannel); } TChannel CreateTransactionChannel(TChannel innerChannel) { if (typeof(TChannel) == typeof(IDuplexSessionChannel)) { return (TChannel)(object) new TransactionDuplexSessionChannel(this, (IDuplexSessionChannel)(object)innerChannel); } else if (typeof(TChannel) == typeof(IRequestSessionChannel)) { return (TChannel)(object) new TransactionRequestSessionChannel(this, (IRequestSessionChannel)(object)innerChannel); } else if (typeof(TChannel) == typeof(IOutputSessionChannel)) { return (TChannel)(object) new TransactionOutputSessionChannel(this, (IOutputSessionChannel)(object)innerChannel); } else if (typeof(TChannel) == typeof(IOutputChannel)) { return (TChannel)(object) new TransactionOutputChannel(this, (IOutputChannel)(object)innerChannel); } else if (typeof(TChannel) == typeof(IRequestChannel)) { return (TChannel)(object) new TransactionRequestChannel(this, (IRequestChannel)(object)innerChannel); } else if (typeof(TChannel) == typeof(IDuplexChannel)) { return (TChannel)(object) new TransactionDuplexChannel(this, (IDuplexChannel)(object)innerChannel); } else { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateChannelTypeNotSupportedException(typeof(TChannel))); } } //=========================================================== // Transaction Output Channel classes //=========================================================== sealed class TransactionOutputChannel : TransactionOutputChannelGeneric { public TransactionOutputChannel(ChannelManagerBase channelManager, IOutputChannel innerChannel) : base(channelManager, innerChannel) { } } sealed class TransactionRequestChannel : TransactionRequestChannelGeneric { public TransactionRequestChannel(ChannelManagerBase channelManager, IRequestChannel innerChannel) : base(channelManager, innerChannel) { } } sealed class TransactionDuplexChannel : TransactionOutputDuplexChannelGeneric { public TransactionDuplexChannel(ChannelManagerBase channelManager, IDuplexChannel innerChannel) : base(channelManager, innerChannel) { } } sealed class TransactionOutputSessionChannel : TransactionOutputChannelGeneric , IOutputSessionChannel { public TransactionOutputSessionChannel(ChannelManagerBase channelManager, IOutputSessionChannel innerChannel) : base(channelManager, innerChannel) { } public IOutputSession Session { get { return InnerChannel.Session; } } } sealed class TransactionRequestSessionChannel : TransactionRequestChannelGeneric , IRequestSessionChannel { public TransactionRequestSessionChannel(ChannelManagerBase channelManager, IRequestSessionChannel innerChannel) : base(channelManager, innerChannel) { } public IOutputSession Session { get { return InnerChannel.Session; } } } sealed class TransactionDuplexSessionChannel : TransactionOutputDuplexChannelGeneric , IDuplexSessionChannel { public TransactionDuplexSessionChannel(ChannelManagerBase channelManager, IDuplexSessionChannel innerChannel) : base(channelManager, innerChannel) { } public IDuplexSession Session { get { return InnerChannel.Session; } } } } static class SecurityStandardsHelper { static SecurityStandardsManager SecurityStandardsManager2007 = CreateStandardsManager(MessageSecurityVersion.WSSecurity11WSTrust13WSSecureConversation13WSSecurityPolicy12); static SecurityStandardsManager CreateStandardsManager(MessageSecurityVersion securityVersion) { return new SecurityStandardsManager( securityVersion, new WSSecurityTokenSerializer(securityVersion.SecurityVersion, securityVersion.TrustVersion, securityVersion.SecureConversationVersion, false, null, null, null)); } public static SecurityStandardsManager CreateStandardsManager(TransactionProtocol transactionProtocol) { if (transactionProtocol == TransactionProtocol.WSAtomicTransactionOctober2004 || transactionProtocol == TransactionProtocol.OleTransactions) { return SecurityStandardsManager.DefaultInstance; } else { return SecurityStandardsHelper.SecurityStandardsManager2007; } } } //============================================================== // Transaction channel base generic classes //============================================================= class TransactionOutputChannelGeneric : TransactionChannel , IOutputChannel where TChannel : class, IOutputChannel { public TransactionOutputChannelGeneric(ChannelManagerBase channelManager, TChannel innerChannel) : base(channelManager, innerChannel) { } public EndpointAddress RemoteAddress { get { return InnerChannel.RemoteAddress; } } public Uri Via { get { return InnerChannel.Via; } } public IAsyncResult BeginSend(Message message, AsyncCallback callback, object state) { return this.BeginSend(message, this.DefaultSendTimeout, callback, state); } public IAsyncResult BeginSend(Message message, TimeSpan timeout, AsyncCallback asyncCallback, object state) { TimeoutHelper timeoutHelper = new TimeoutHelper(timeout); WriteTransactionDataToMessage(message, MessageDirection.Input); return InnerChannel.BeginSend(message, timeoutHelper.RemainingTime(), asyncCallback, state); } public void EndSend(IAsyncResult result) { InnerChannel.EndSend(result); } public void Send(Message message) { this.Send(message, this.DefaultSendTimeout); } public void Send(Message message, TimeSpan timeout) { TimeoutHelper timeoutHelper = new TimeoutHelper(timeout); WriteTransactionDataToMessage(message, MessageDirection.Input); InnerChannel.Send(message, timeoutHelper.RemainingTime()); } } class TransactionRequestChannelGeneric : TransactionChannel , IRequestChannel where TChannel : class, IRequestChannel { public TransactionRequestChannelGeneric(ChannelManagerBase channelManager, TChannel innerChannel) : base(channelManager, innerChannel) { } public EndpointAddress RemoteAddress { get { return InnerChannel.RemoteAddress; } } public Uri Via { get { return InnerChannel.Via; } } public IAsyncResult BeginRequest(Message message, AsyncCallback callback, object state) { return this.BeginRequest(message, this.DefaultSendTimeout, callback, state); } public IAsyncResult BeginRequest(Message message, TimeSpan timeout, AsyncCallback asyncCallback, object state) { TimeoutHelper timeoutHelper = new TimeoutHelper(timeout); WriteTransactionDataToMessage(message, MessageDirection.Input); return InnerChannel.BeginRequest(message, timeoutHelper.RemainingTime(), asyncCallback, state); } public Message EndRequest(IAsyncResult result) { Message reply = InnerChannel.EndRequest(result); if (reply != null) this.ReadIssuedTokens(reply, MessageDirection.Output); return reply; } public Message Request(Message message) { return this.Request(message, this.DefaultSendTimeout); } public Message Request(Message message, TimeSpan timeout) { TimeoutHelper timeoutHelper = new TimeoutHelper(timeout); WriteTransactionDataToMessage(message, MessageDirection.Input); Message reply = InnerChannel.Request(message, timeoutHelper.RemainingTime()); if (reply != null) this.ReadIssuedTokens(reply, MessageDirection.Output); return reply; } } class TransactionOutputDuplexChannelGeneric : TransactionDuplexChannelGeneric where TChannel : class, IDuplexChannel { public TransactionOutputDuplexChannelGeneric(ChannelManagerBase channelManager, TChannel innerChannel) : base(channelManager, innerChannel, MessageDirection.Output) { } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- DateTimeFormatInfo.cs
- RegistrySecurity.cs
- SystemInfo.cs
- DataGridViewColumnHeaderCell.cs
- SelectionPattern.cs
- ByteStorage.cs
- ResourceCategoryAttribute.cs
- _SslSessionsCache.cs
- XmlSortKey.cs
- FieldNameLookup.cs
- IndexedGlyphRun.cs
- DependencyObjectType.cs
- DTCTransactionManager.cs
- SqlProfileProvider.cs
- EntityClassGenerator.cs
- ExitEventArgs.cs
- ColumnBinding.cs
- ValueUnavailableException.cs
- BindableTemplateBuilder.cs
- MaskInputRejectedEventArgs.cs
- NavigationPropertyEmitter.cs
- EventToken.cs
- MachineKeySection.cs
- CommonRemoteMemoryBlock.cs
- VideoDrawing.cs
- HtmlInputHidden.cs
- coordinatorfactory.cs
- TemporaryBitmapFile.cs
- _SafeNetHandles.cs
- OuterGlowBitmapEffect.cs
- MetadataImporter.cs
- ExtenderControl.cs
- OleDbConnectionInternal.cs
- IHttpResponseInternal.cs
- COM2Enum.cs
- CookieProtection.cs
- Blend.cs
- ValidatorCompatibilityHelper.cs
- Vertex.cs
- NullableIntAverageAggregationOperator.cs
- CrossSiteScriptingValidation.cs
- OrCondition.cs
- SmiGettersStream.cs
- ProfileSettings.cs
- AnnotationAuthorChangedEventArgs.cs
- DataControlButton.cs
- PointLightBase.cs
- RC2.cs
- LayoutEvent.cs
- SystemParameters.cs
- KeyGestureValueSerializer.cs
- BinaryReader.cs
- HttpHeaderCollection.cs
- SuppressMessageAttribute.cs
- Pair.cs
- ToolBarPanel.cs
- CqlLexer.cs
- OLEDB_Util.cs
- DiscoveryDocumentSerializer.cs
- RSAPKCS1KeyExchangeFormatter.cs
- HttpResponseBase.cs
- BmpBitmapDecoder.cs
- TextElement.cs
- HtmlControlPersistable.cs
- MimeObjectFactory.cs
- EndpointDiscoveryMetadataCD1.cs
- FrameworkElementFactoryMarkupObject.cs
- RealizationContext.cs
- ReadOnlyCollectionBase.cs
- IncrementalHitTester.cs
- StringFormat.cs
- MatrixUtil.cs
- PerformanceCountersElement.cs
- safemediahandle.cs
- ApplicationFileCodeDomTreeGenerator.cs
- ConfigurationCollectionAttribute.cs
- GenericUriParser.cs
- SimpleBitVector32.cs
- DesignerTransactionCloseEvent.cs
- WebAdminConfigurationHelper.cs
- FixedHighlight.cs
- RIPEMD160Managed.cs
- MainMenu.cs
- UserControlFileEditor.cs
- GB18030Encoding.cs
- Regex.cs
- TextTreeExtractElementUndoUnit.cs
- Symbol.cs
- HealthMonitoringSectionHelper.cs
- EntityCommand.cs
- ExcCanonicalXml.cs
- TextElementEditingBehaviorAttribute.cs
- KerberosSecurityTokenProvider.cs
- StatementContext.cs
- AssertFilter.cs
- FontUnit.cs
- AndCondition.cs
- ListViewCancelEventArgs.cs
- FunctionMappingTranslator.cs
- CqlErrorHelper.cs