Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / NetTcpSecurity.cs / 1 / NetTcpSecurity.cs
//------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.ServiceModel { using System.Diagnostics; using System.Net.Security; using System.ServiceModel.Channels; using System.ServiceModel.Security; using System.ServiceModel.Configuration; public sealed class NetTcpSecurity { internal const SecurityMode DefaultMode = SecurityMode.Transport; SecurityMode mode; TcpTransportSecurity transportSecurity; MessageSecurityOverTcp messageSecurity; internal NetTcpSecurity() : this(DefaultMode, new TcpTransportSecurity(), new MessageSecurityOverTcp()) { } NetTcpSecurity(SecurityMode mode, TcpTransportSecurity transportSecurity, MessageSecurityOverTcp messageSecurity) { DiagnosticUtility.DebugAssert(SecurityModeHelper.IsDefined(mode), string.Format("Invalid SecurityMode value: {0}.", mode.ToString())); this.mode = mode; this.transportSecurity = transportSecurity == null ? new TcpTransportSecurity() : transportSecurity; this.messageSecurity = messageSecurity == null ? new MessageSecurityOverTcp() : messageSecurity; } public SecurityMode Mode { get { return this.mode; } set { if (!SecurityModeHelper.IsDefined(value)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value")); } this.mode = value; } } public TcpTransportSecurity Transport { get { return this.transportSecurity; } } public MessageSecurityOverTcp Message { get { return this.messageSecurity; } } internal BindingElement CreateTransportSecurity() { if (this.mode == SecurityMode.TransportWithMessageCredential) { return this.transportSecurity.CreateTransportProtectionOnly(); } else if (this.mode == SecurityMode.Transport) { return this.transportSecurity.CreateTransportProtectionAndAuthentication(); } else { return null; } } internal static UnifiedSecurityMode GetModeFromTransportSecurity(BindingElement transport) { if (transport == null) { return UnifiedSecurityMode.None | UnifiedSecurityMode.Message; } else { return UnifiedSecurityMode.TransportWithMessageCredential | UnifiedSecurityMode.Transport; } } internal static bool SetTransportSecurity(BindingElement transport, SecurityMode mode, TcpTransportSecurity transportSecurity) { if (mode == SecurityMode.TransportWithMessageCredential) { return TcpTransportSecurity.SetTransportProtectionOnly(transport, transportSecurity); } else if (mode == SecurityMode.Transport) { return TcpTransportSecurity.SetTransportProtectionAndAuthentication(transport, transportSecurity); } return transport == null; } internal SecurityBindingElement CreateMessageSecurity(bool isReliableSessionEnabled) { if (this.mode == SecurityMode.Message) { return this.messageSecurity.CreateSecurityBindingElement(false, isReliableSessionEnabled, null); } else if (this.mode == SecurityMode.TransportWithMessageCredential) { return this.messageSecurity.CreateSecurityBindingElement(true, isReliableSessionEnabled, this.CreateTransportSecurity()); } else { return null; } } internal static bool TryCreate(SecurityBindingElement wsSecurity, SecurityMode mode, bool isReliableSessionEnabled, BindingElement transportSecurity, TcpTransportSecurity tcpTransportSecurity, out NetTcpSecurity security) { security = null; MessageSecurityOverTcp messageSecurity = null; if (mode == SecurityMode.Message) { if (!MessageSecurityOverTcp.TryCreate(wsSecurity, isReliableSessionEnabled, null, out messageSecurity)) return false; } else if (mode == SecurityMode.TransportWithMessageCredential) { if (!MessageSecurityOverTcp.TryCreate(wsSecurity, isReliableSessionEnabled, transportSecurity, out messageSecurity)) return false; } security = new NetTcpSecurity(mode, tcpTransportSecurity, messageSecurity); return SecurityElement.AreBindingsMatching(security.CreateMessageSecurity(isReliableSessionEnabled), wsSecurity, false); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
![Network programming in C#, Network Programming in VB.NET, Network Programming in .NET](/images/book.jpg)
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- AttachmentCollection.cs
- ParameterRetriever.cs
- TextEmbeddedObject.cs
- DataGridViewColumnEventArgs.cs
- ServiceReference.cs
- newinstructionaction.cs
- TextDecorationCollection.cs
- ECDiffieHellman.cs
- RbTree.cs
- FieldBuilder.cs
- SHA512.cs
- XappLauncher.cs
- BackoffTimeoutHelper.cs
- WindowsToolbarAsMenu.cs
- SqlDataSourceCommandEventArgs.cs
- EventListener.cs
- ProcessDesigner.cs
- StrictModeSecurityHeaderElementInferenceEngine.cs
- DbRetry.cs
- GroupLabel.cs
- BrowserCapabilitiesCodeGenerator.cs
- HighContrastHelper.cs
- DesignSurfaceManager.cs
- Label.cs
- LocalTransaction.cs
- WebControlsSection.cs
- PublishLicense.cs
- FileCodeGroup.cs
- ResourceReferenceExpressionConverter.cs
- CounterCreationData.cs
- GridViewUpdateEventArgs.cs
- UserPreferenceChangingEventArgs.cs
- HttpCacheVary.cs
- CacheModeConverter.cs
- ValidationError.cs
- BatchParser.cs
- ProviderConnectionPointCollection.cs
- XPathNode.cs
- odbcmetadatafactory.cs
- ComplexBindingPropertiesAttribute.cs
- StylusEventArgs.cs
- MimeTypePropertyAttribute.cs
- ListItemParagraph.cs
- COM2ExtendedBrowsingHandler.cs
- InterleavedZipPartStream.cs
- SRGSCompiler.cs
- XmlQueryTypeFactory.cs
- FixedSOMTable.cs
- GridSplitterAutomationPeer.cs
- StrongNamePublicKeyBlob.cs
- TransportSecurityProtocolFactory.cs
- KeyInstance.cs
- TextureBrush.cs
- EditorZoneDesigner.cs
- DateTimeConstantAttribute.cs
- Form.cs
- TextTreeInsertUndoUnit.cs
- LowerCaseStringConverter.cs
- TextEvent.cs
- MimeTypeMapper.cs
- CheckBoxRenderer.cs
- Converter.cs
- Image.cs
- DecimalFormatter.cs
- CompositionAdorner.cs
- DataGridViewSelectedCellsAccessibleObject.cs
- EUCJPEncoding.cs
- Registry.cs
- TabControlAutomationPeer.cs
- RadioButtonList.cs
- WindowsScrollBar.cs
- Setter.cs
- CodeMemberMethod.cs
- SingleResultAttribute.cs
- loginstatus.cs
- ToolBarButton.cs
- ModelUIElement3D.cs
- IISUnsafeMethods.cs
- QueryTask.cs
- Group.cs
- CryptoKeySecurity.cs
- HttpCacheParams.cs
- Cell.cs
- Parsers.cs
- __ComObject.cs
- SystemDiagnosticsSection.cs
- SessionEndedEventArgs.cs
- Transform3DGroup.cs
- FileVersionInfo.cs
- NameValueFileSectionHandler.cs
- SoapFault.cs
- PtsPage.cs
- HttpPostProtocolImporter.cs
- XNameTypeConverter.cs
- EmptyControlCollection.cs
- SynchronizationContext.cs
- ToolBar.cs
- WebHttpEndpointElement.cs
- DomainConstraint.cs
- UnknownBitmapDecoder.cs