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
- XmlStreamNodeWriter.cs
- XmlSchemaAttributeGroup.cs
- Setter.cs
- EventSchemaTraceListener.cs
- ProcessThread.cs
- ColorAnimationUsingKeyFrames.cs
- MediaCommands.cs
- SQLByteStorage.cs
- HttpRequest.cs
- EditingScopeUndoUnit.cs
- WaitForChangedResult.cs
- CodeTypeParameterCollection.cs
- Utils.cs
- UserNameSecurityTokenProvider.cs
- TraceEventCache.cs
- DataControlField.cs
- MiniAssembly.cs
- UnsafeNativeMethods.cs
- FontFamily.cs
- XmlSchemaCompilationSettings.cs
- DbBuffer.cs
- SqlTypesSchemaImporter.cs
- ContentPresenter.cs
- UnaryQueryOperator.cs
- NamedElement.cs
- FormViewDeleteEventArgs.cs
- SpecularMaterial.cs
- AgileSafeNativeMemoryHandle.cs
- Crc32Helper.cs
- SmiConnection.cs
- HttpPostProtocolReflector.cs
- PageFunction.cs
- Membership.cs
- OrderByBuilder.cs
- ObjectListFieldsPage.cs
- TextTreeRootNode.cs
- WebBrowserSiteBase.cs
- AccessibleObject.cs
- SqlRowUpdatedEvent.cs
- XmlWrappingReader.cs
- DbParameterCollectionHelper.cs
- FilterException.cs
- Scalars.cs
- VBCodeProvider.cs
- AffineTransform3D.cs
- ExpressionBindingCollection.cs
- MessagePropertyVariants.cs
- UmAlQuraCalendar.cs
- TreeViewItemAutomationPeer.cs
- ParameterCollection.cs
- Query.cs
- PasswordValidationException.cs
- PropertyMetadata.cs
- UnionCodeGroup.cs
- MULTI_QI.cs
- EtwTrace.cs
- SqlUnionizer.cs
- TreeNodeCollectionEditor.cs
- Pen.cs
- IteratorFilter.cs
- WithStatement.cs
- SQLInt16Storage.cs
- GridViewRowEventArgs.cs
- FieldToken.cs
- StatusBarAutomationPeer.cs
- WebPartAddingEventArgs.cs
- WebConfigurationHost.cs
- XmlSchemaFacet.cs
- SafeNativeMethods.cs
- GeneratedView.cs
- CompositeScriptReferenceEventArgs.cs
- SafeEventLogReadHandle.cs
- ManifestBasedResourceGroveler.cs
- MouseCaptureWithinProperty.cs
- ArgumentException.cs
- ShellProvider.cs
- DataGridViewMethods.cs
- DispatcherOperation.cs
- LocalizabilityAttribute.cs
- PathFigureCollection.cs
- ExeConfigurationFileMap.cs
- DataGridPagerStyle.cs
- StandardRuntimeEnumValidator.cs
- SqlTriggerContext.cs
- LocalizableResourceBuilder.cs
- UriSection.cs
- ServiceModelConfiguration.cs
- ReachFixedPageSerializerAsync.cs
- Int32AnimationUsingKeyFrames.cs
- ChangeBlockUndoRecord.cs
- TabControlToolboxItem.cs
- WindowsGrip.cs
- SqlPersistenceWorkflowInstanceDescription.cs
- SoapAttributeAttribute.cs
- AlgoModule.cs
- XPathScanner.cs
- FamilyMap.cs
- ObjectManager.cs
- StylusButtonCollection.cs
- PageRanges.cs