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
- BaseUriHelper.cs
- AncillaryOps.cs
- XmlSchemaRedefine.cs
- DocumentScope.cs
- CannotUnloadAppDomainException.cs
- DataGridViewLinkCell.cs
- XPathExpr.cs
- Matrix.cs
- LabelLiteral.cs
- EntityReference.cs
- CounterNameConverter.cs
- Codec.cs
- SiteOfOriginPart.cs
- GenericEnumConverter.cs
- _Rfc2616CacheValidators.cs
- WriteableBitmap.cs
- ContentPresenter.cs
- Timer.cs
- PerformanceCounterTraceRecord.cs
- LineSegment.cs
- NativeMethodsOther.cs
- CharAnimationBase.cs
- ParameterReplacerVisitor.cs
- AssemblyResourceLoader.cs
- SerializationInfoEnumerator.cs
- AnimationStorage.cs
- UnconditionalPolicy.cs
- SQLResource.cs
- IndentTextWriter.cs
- AudioStateChangedEventArgs.cs
- FlowDocumentScrollViewerAutomationPeer.cs
- SelectedPathEditor.cs
- TabControlAutomationPeer.cs
- KnownIds.cs
- UnknownBitmapDecoder.cs
- SecurityBindingElementImporter.cs
- HtmlShim.cs
- _NetworkingPerfCounters.cs
- DataServiceRequestOfT.cs
- RoutedPropertyChangedEventArgs.cs
- VectorCollectionValueSerializer.cs
- SendingRequestEventArgs.cs
- DbDataSourceEnumerator.cs
- httpapplicationstate.cs
- CodeTypeReference.cs
- CompiledQueryCacheKey.cs
- ViewStateException.cs
- XDRSchema.cs
- AppliedDeviceFiltersDialog.cs
- InstallerTypeAttribute.cs
- storepermission.cs
- ChangeInterceptorAttribute.cs
- ColumnMapVisitor.cs
- XmlStreamStore.cs
- DataGridViewTopRowAccessibleObject.cs
- TableDetailsRow.cs
- SqlClientFactory.cs
- Composition.cs
- AuthenticationModuleElement.cs
- OletxTransactionFormatter.cs
- CompilerGlobalScopeAttribute.cs
- DeclarativeExpressionConditionDeclaration.cs
- ContractReference.cs
- DataListItem.cs
- ETagAttribute.cs
- TableCell.cs
- Rule.cs
- BindingNavigator.cs
- XmlObjectSerializerWriteContextComplex.cs
- SystemColors.cs
- StateBag.cs
- SolidBrush.cs
- XMLSchema.cs
- DataObjectEventArgs.cs
- TextSyndicationContent.cs
- XmlReaderDelegator.cs
- SeverityFilter.cs
- UnSafeCharBuffer.cs
- TableRowGroup.cs
- PermissionSet.cs
- DbParameterHelper.cs
- PipeSecurity.cs
- StringFunctions.cs
- TaskFormBase.cs
- ProviderCollection.cs
- TextEncodedRawTextWriter.cs
- ResourceDisplayNameAttribute.cs
- EditorPartCollection.cs
- PersonalizableAttribute.cs
- TdsParserSessionPool.cs
- Cursors.cs
- EventManager.cs
- UserNameSecurityToken.cs
- StringConcat.cs
- PackUriHelper.cs
- MessageDecoder.cs
- ProxyWebPartManager.cs
- AuthenticateEventArgs.cs
- BadImageFormatException.cs
- FragmentQueryKB.cs