Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Transactions / WsatTransactionFormatter.cs / 2 / WsatTransactionFormatter.cs
//------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.ServiceModel.Transactions { using System; using System.Collections.Generic; using System.Diagnostics; using System.ServiceModel; using System.ServiceModel.Channels; using System.ServiceModel.Security; using System.Threading; using System.Transactions; using System.Xml; using Microsoft.Transactions.Bridge; using Microsoft.Transactions.Wsat.Messaging; using Microsoft.Transactions.Wsat.Protocol; using Microsoft.Win32; using DiagnosticUtility = System.ServiceModel.DiagnosticUtility; abstract class WsatTransactionFormatter : TransactionFormatter { bool initialized; WsatConfiguration wsatConfig; WsatProxy wsatProxy; ProtocolVersion protocolVersion; protected WsatTransactionFormatter(ProtocolVersion protocolVersion) { this.protocolVersion = protocolVersion; } //======================================================================================= void EnsureInitialized() { if (!this.initialized) { lock (this) { if (!this.initialized) { this.wsatConfig = new WsatConfiguration(); this.wsatProxy = new WsatProxy(this.wsatConfig, this.protocolVersion); this.initialized = true; } } } } //======================================================================================= public override void WriteTransaction(Transaction transaction, Message message) { EnsureInitialized(); ForcePromotion(transaction); // Make a context and add it to the message CoordinationContext context; RequestSecurityTokenResponse issuedToken; MarshalAsCoordinationContext(transaction, out context, out issuedToken); if (issuedToken != null) { CoordinationServiceSecurity.AddIssuedToken(message, issuedToken); } WsatTransactionHeader header = new WsatTransactionHeader(context, this.protocolVersion); message.Headers.Add(header); } //======================================================================================== void ForcePromotion(Transaction transaction) { // Force promotion. This may throw TransactionException. // We used to check the DistributedIdentifier property first, but VSWhidbey bug 547901 // prevents us from doing so reliably in multi-threaded scenarios (there is a race // in the System.Transactions code that can cause a NullReferenceException if we ask // for the identifier while the transaction is being promoted) TransactionInterop.GetTransmitterPropagationToken(transaction); } //======================================================================================= public override TransactionInfo ReadTransaction(Message message) { EnsureInitialized(); CoordinationContext context = WsatTransactionHeader.GetCoordinationContext(message, this.protocolVersion); if (context == null) return null; // Incoming transaction tokens are optional RequestSecurityTokenResponse issuedToken; try { issuedToken = CoordinationServiceSecurity.GetIssuedToken(message, context.Identifier, this.protocolVersion); } catch (XmlException e) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError( new TransactionException(SR.FailedToDeserializeIssuedToken, e)); } return new WsatTransactionInfo(this.wsatProxy, context, issuedToken); } //======================================================================================== public WsatTransactionInfo CreateTransactionInfo(CoordinationContext context, RequestSecurityTokenResponse issuedToken) { return new WsatTransactionInfo(this.wsatProxy, context, issuedToken); } //======================================================================================== public void MarshalAsCoordinationContext(Transaction transaction, out CoordinationContext context, out RequestSecurityTokenResponse issuedToken) { Guid transactionId = transaction.TransactionInformation.DistributedIdentifier; string nonNativeContextId = null; context = new CoordinationContext(this.protocolVersion); // Get timeout, description and isolation flags uint timeout; IsolationFlags isoFlags; string description; OleTxTransactionFormatter.GetTransactionAttributes(transaction, out timeout, out isoFlags, out description); context.IsolationFlags = isoFlags; context.Description = description; // If we can, use cached extended information // Note - it may be worth using outgoing contexts more than once. // We'll let performance profiling decide that question WsatExtendedInformation info; if (WsatExtendedInformationCache.Find(transaction, out info)) { context.Expires = info.Timeout; // The extended info cache only contains an identifier when it's non-native if (!string.IsNullOrEmpty(info.Identifier)) { context.Identifier = info.Identifier; nonNativeContextId = info.Identifier; } } else { context.Expires = timeout; if (context.Expires == 0) { // If the timeout is zero, there are two possibilities: // 1) This is a root transaction with an infinite timeout. // 2) This is a subordinate transaction whose timeout was not flowed. // We have no mechanism for distinguishing between the two cases. // // We could always return zero here, instead of using the local max timeout. // The problem is that the 2004/08 WS-C spec does not specify the meaning // of a zero expires field. While we accept zero to mean "as large as possible" // it would be risky to expect others to do the same. So we only propagate // zero in the expires field if the local max timeout has been disabled. // // This is MB 34596: how can we flow the real timeout? context.Expires = (uint)TimeoutHelper.ToMilliseconds(this.wsatConfig.MaxTimeout); } } if (context.Identifier == null) { context.Identifier = CoordinationContext.CreateNativeIdentifier(transactionId); nonNativeContextId = null; } string tokenId; if (!this.wsatConfig.IssuedTokensEnabled) { tokenId = null; issuedToken = null; } else { CoordinationServiceSecurity.CreateIssuedToken(transactionId, context.Identifier, this.protocolVersion, out issuedToken, out tokenId); } AddressHeader refParam = new WsatRegistrationHeader(transactionId, nonNativeContextId, tokenId); context.RegistrationService = wsatConfig.CreateRegistrationService(refParam, this.protocolVersion); context.IsolationLevel = transaction.IsolationLevel; context.LocalTransactionId = transactionId; if (this.wsatConfig.OleTxUpgradeEnabled) { context.PropagationToken = TransactionInterop.GetTransmitterPropagationToken(transaction); } } } //----------------------------------------------------------------------------------------- // Versioned Wsat transaction formatters //------------------------------------------------------------------------------------------ class WsatTransactionFormatter10 : WsatTransactionFormatter { static WsatTransactionHeader emptyTransactionHeader = new WsatTransactionHeader(null, ProtocolVersion.Version10); public WsatTransactionFormatter10() : base(ProtocolVersion.Version10) {} //======================================================================================= public override MessageHeader EmptyTransactionHeader { get { return emptyTransactionHeader; } } } class WsatTransactionFormatter11 : WsatTransactionFormatter { static WsatTransactionHeader emptyTransactionHeader = new WsatTransactionHeader(null, ProtocolVersion.Version11); public WsatTransactionFormatter11() : base(ProtocolVersion.Version11) {} //======================================================================================= public override MessageHeader EmptyTransactionHeader { get { return emptyTransactionHeader; } } } } // 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
- CustomExpression.cs
- RSAOAEPKeyExchangeFormatter.cs
- VisualStateManager.cs
- XslTransform.cs
- AssociationSetEnd.cs
- XmlCharCheckingReader.cs
- FormView.cs
- Queue.cs
- ListItemsCollectionEditor.cs
- CreateDataSourceDialog.cs
- RepeaterCommandEventArgs.cs
- HMACSHA512.cs
- HttpCachePolicy.cs
- DataGridViewAutoSizeColumnModeEventArgs.cs
- EndpointDiscoveryElement.cs
- MachineKey.cs
- MenuItemBindingCollection.cs
- ClientFormsIdentity.cs
- UnsignedPublishLicense.cs
- _NegoStream.cs
- ConnectionManager.cs
- NameSpaceExtractor.cs
- SerializeAbsoluteContext.cs
- ApplicationManager.cs
- BaseCAMarshaler.cs
- TranslateTransform.cs
- LineBreakRecord.cs
- EmptyReadOnlyDictionaryInternal.cs
- ResourceExpressionBuilder.cs
- GradientBrush.cs
- CommandSet.cs
- TextTrailingCharacterEllipsis.cs
- CommandEventArgs.cs
- XhtmlBasicPanelAdapter.cs
- StateMachine.cs
- TimeoutHelper.cs
- StandardBindingReliableSessionElement.cs
- ToolStripMenuItem.cs
- ParseNumbers.cs
- BinarySerializer.cs
- Win32SafeHandles.cs
- EntityDataSource.cs
- CommaDelimitedStringAttributeCollectionConverter.cs
- FileChangesMonitor.cs
- CustomAttributeSerializer.cs
- Byte.cs
- SqlParameterCollection.cs
- TextEffectResolver.cs
- RawUIStateInputReport.cs
- OdbcDataAdapter.cs
- SafeNativeMethods.cs
- ContentDisposition.cs
- MenuEventArgs.cs
- PaginationProgressEventArgs.cs
- serverconfig.cs
- AssemblyName.cs
- DesignBindingEditor.cs
- DetailsViewRowCollection.cs
- CheckBoxRenderer.cs
- DependentList.cs
- AnyReturnReader.cs
- RelatedImageListAttribute.cs
- AuthenticationModuleElement.cs
- RelatedCurrencyManager.cs
- TableRowCollection.cs
- WebBrowserDocumentCompletedEventHandler.cs
- Trustee.cs
- CustomErrorCollection.cs
- WindowsIdentity.cs
- StringPropertyBuilder.cs
- SqlUtils.cs
- XmlDictionaryReaderQuotasElement.cs
- WindowsAltTab.cs
- ConfigurationConverterBase.cs
- RunInstallerAttribute.cs
- _NetworkingPerfCounters.cs
- recordstate.cs
- HuffCodec.cs
- FileDialog_Vista.cs
- DiagnosticsConfigurationHandler.cs
- PathData.cs
- ContextMarshalException.cs
- ListenerConfig.cs
- StrokeNodeEnumerator.cs
- mactripleDES.cs
- NotifyCollectionChangedEventArgs.cs
- DocumentViewerConstants.cs
- ActionFrame.cs
- Block.cs
- Animatable.cs
- ItemChangedEventArgs.cs
- ControlBuilderAttribute.cs
- EntityTypeBase.cs
- TileBrush.cs
- SortDescriptionCollection.cs
- HtmlElement.cs
- HMACSHA256.cs
- CodeGenerator.cs
- HtmlImage.cs
- DocumentReference.cs