Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Channels / TransactionChannel.cs / 1 / TransactionChannel.cs
//---------------------------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. //--------------------------------------------------------------------------- namespace System.ServiceModel.Channels { using System.Collections.Generic; using System.ServiceModel.Description; using System.Diagnostics; using System.ServiceModel; using System.ServiceModel.Security; using System.Transactions; using System.ServiceModel.Transactions; using System.Runtime.CompilerServices; using System.Runtime.Remoting; using System.Runtime.Remoting.Messaging; using SR=System.ServiceModel.SR; using System.ServiceModel.Diagnostics; internal interface ITransactionChannel { // These get run on forward-going messages only void WriteTransactionDataToMessage(Message message, MessageDirection direction); void ReadTransactionDataFromMessage(Message message, MessageDirection direction); // These get run in both directions (request and reply). If other flowable-things are added // that need to flow both ways, these methods should be renamed and generalized to do it void ReadIssuedTokens(Message message, MessageDirection direction); void WriteIssuedTokens(Message message, MessageDirection direction); } abstract class TransactionChannel: LayeredChannel , ITransactionChannel where TChannel : class, IChannel { ITransactionChannelManager factory; TransactionFormatter formatter; protected TransactionChannel(ChannelManagerBase channelManager, TChannel innerChannel) : base(channelManager, innerChannel) { this.factory = (ITransactionChannelManager)channelManager; if (this.factory.TransactionProtocol == TransactionProtocol.OleTransactions) { this.formatter = TransactionFormatter.OleTxFormatter; } else if (this.factory.TransactionProtocol == TransactionProtocol.WSAtomicTransactionOctober2004) { this.formatter = TransactionFormatter.WsatFormatter10; } else if (this.factory.TransactionProtocol == TransactionProtocol.WSAtomicTransaction11) { this.formatter = TransactionFormatter.WsatFormatter11; } else { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError( new ArgumentException(SR.GetString(SR.SFxBadTransactionProtocols))); } } internal TransactionFormatter Formatter { get { return this.formatter; } } internal TransactionProtocol Protocol { get { return this.factory.TransactionProtocol; } } public override T GetProperty () { if(typeof(T) == typeof(FaultConverter)) { return (T)(object) new TransactionChannelFaultConverter (this); } return base.GetProperty (); } public T GetInnerProperty () where T : class { return base.InnerChannel.GetProperty (); } static bool Found(int index) { return index != -1; } void FaultOnMessage(Message message, string reason, string codeString) { FaultCode code = FaultCode.CreateSenderFaultCode(codeString, FaultCodeConstants.Namespaces.Transactions); FaultException fault = new FaultException(reason, code, FaultCodeConstants.Actions.Transactions); throw TraceUtility.ThrowHelperError(fault, message); } ICollection GetIssuedTokens(Message message) { return IssuedTokensHeader.ExtractIssuances(message, this.factory.StandardsManager, message.Version.Envelope.UltimateDestinationActorValues, null); } public void ReadIssuedTokens(Message message, MessageDirection direction) { TransactionFlowOption option = this.factory.FlowIssuedTokens; ICollection issuances = this.GetIssuedTokens(message); if (issuances != null && issuances.Count != 0) { if (option == TransactionFlowOption.NotAllowed) { FaultOnMessage(message, SR.GetString(SR.IssuedTokenFlowNotAllowed), FaultCodeConstants.Codes.IssuedTokenFlowNotAllowed); } foreach (RequestSecurityTokenResponse rstr in issuances) { TransactionFlowProperty.Ensure(message).IssuedTokens.Add(rstr); } } } void ReadTransactionFromMessage(Message message, TransactionFlowOption txFlowOption) { TransactionInfo transactionInfo = null; try { transactionInfo = this.formatter.ReadTransaction(message); } catch (TransactionException e) { DiagnosticUtility.ExceptionUtility.TraceHandledException(e, TraceEventType.Error); FaultOnMessage(message, SR.GetString(SR.SFxTransactionDeserializationFailed, e.Message), FaultCodeConstants.Codes.TransactionHeaderMalformed); } if (transactionInfo != null) { TransactionMessageProperty.Set(transactionInfo, message); } else if (txFlowOption == TransactionFlowOption.Mandatory) { FaultOnMessage(message, SR.GetString(SR.SFxTransactionFlowRequired), FaultCodeConstants.Codes.TransactionHeaderMissing); } } public virtual void ReadTransactionDataFromMessage(Message message, MessageDirection direction) { this.ReadIssuedTokens(message, direction); TransactionFlowOption txFlowOption = this.factory.GetTransaction(direction, message.Headers.Action); if (TransactionFlowOptionHelper.AllowedOrRequired(txFlowOption)) { this.ReadTransactionFromMessage(message, txFlowOption); } } public void WriteTransactionDataToMessage(Message message, MessageDirection direction) { TransactionFlowOption txFlowOption = this.factory.GetTransaction(direction, message.Headers.Action); if (TransactionFlowOptionHelper.AllowedOrRequired(txFlowOption)) { this.WriteTransactionToMessage(message, txFlowOption); } if (TransactionFlowOptionHelper.AllowedOrRequired(this.factory.FlowIssuedTokens)) { this.WriteIssuedTokens(message, direction); } } [MethodImpl(MethodImplOptions.NoInlining)] void WriteTransactionToMessage(Message message, TransactionFlowOption txFlowOption) { Transaction transaction = TransactionFlowProperty.TryGetTransaction(message); if (transaction != null) { try { this.formatter.WriteTransaction(transaction, message); } catch (TransactionException e) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ProtocolException(e.Message, e)); } } else if (txFlowOption == TransactionFlowOption.Mandatory) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ProtocolException(SR.GetString(SR.SFxTransactionFlowRequired))); } } public void WriteIssuedTokens(Message message, MessageDirection direction) { ICollection issuances = TransactionFlowProperty.TryGetIssuedTokens(message); if (issuances != null) { IssuedTokensHeader header = new IssuedTokensHeader(issuances, this.factory.StandardsManager); message.Headers.Add(header); } } } } // 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
- AssemblyBuilder.cs
- CompositionTarget.cs
- ReflectionServiceProvider.cs
- Matrix3DConverter.cs
- IssuedTokenClientBehaviorsElement.cs
- ResourceProviderFactory.cs
- ControlIdConverter.cs
- MailAddressCollection.cs
- DbSource.cs
- Win32.cs
- CheckBoxStandardAdapter.cs
- SemanticAnalyzer.cs
- CompatibleIComparer.cs
- ScrollPattern.cs
- ArgumentOutOfRangeException.cs
- BrowserCapabilitiesFactory.cs
- EventListener.cs
- ToolStripSplitButton.cs
- SystemIcmpV6Statistics.cs
- UInt32.cs
- StreamingContext.cs
- TemplateControlCodeDomTreeGenerator.cs
- DataMisalignedException.cs
- ToolBar.cs
- ObjectCache.cs
- Material.cs
- XhtmlBasicPhoneCallAdapter.cs
- ObjectViewFactory.cs
- WindowsComboBox.cs
- WebConfigurationHost.cs
- AppDomainProtocolHandler.cs
- AffineTransform3D.cs
- StructureChangedEventArgs.cs
- WebPartPersonalization.cs
- DetailsViewInsertedEventArgs.cs
- TagMapCollection.cs
- ChannelManager.cs
- TrackingQueryElement.cs
- DesignTimeDataBinding.cs
- TextRenderer.cs
- WaitHandleCannotBeOpenedException.cs
- CustomSignedXml.cs
- WindowProviderWrapper.cs
- Component.cs
- AutoGeneratedFieldProperties.cs
- OleAutBinder.cs
- FeatureSupport.cs
- CollectionChangeEventArgs.cs
- DataGridViewCheckBoxCell.cs
- TypeInitializationException.cs
- ScaleTransform3D.cs
- DeleteBookmarkScope.cs
- ConfigXmlAttribute.cs
- DefaultEvaluationContext.cs
- DropShadowEffect.cs
- SmiRecordBuffer.cs
- HighContrastHelper.cs
- DefaultAsyncDataDispatcher.cs
- SrgsDocumentParser.cs
- TreeNodeStyle.cs
- CallbackValidatorAttribute.cs
- Lease.cs
- Vector3DCollection.cs
- DbProviderFactories.cs
- DataGridParentRows.cs
- ScriptModule.cs
- IntSecurity.cs
- RegionIterator.cs
- BamlResourceSerializer.cs
- MeshGeometry3D.cs
- TreeIterator.cs
- DateTimeValueSerializerContext.cs
- FontWeights.cs
- ProtocolsConfigurationEntry.cs
- LOSFormatter.cs
- ConsoleCancelEventArgs.cs
- DataControlPagerLinkButton.cs
- ListMarkerLine.cs
- StringToken.cs
- GeometryGroup.cs
- DefaultCompensation.cs
- ConfigurationManagerHelperFactory.cs
- DesignerActionUI.cs
- DebugInfoGenerator.cs
- CheckableControlBaseAdapter.cs
- DriveNotFoundException.cs
- CharacterString.cs
- ResourceDefaultValueAttribute.cs
- SimplePropertyEntry.cs
- DataGridViewRowHeaderCell.cs
- Matrix3DConverter.cs
- RewritingSimplifier.cs
- SqlDataReader.cs
- Version.cs
- ToolStripSettings.cs
- PrintControllerWithStatusDialog.cs
- ArraySet.cs
- IndexedWhereQueryOperator.cs
- StreamInfo.cs
- OrderingExpression.cs