Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Channels / Binding.cs / 1 / Binding.cs
//------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- namespace System.ServiceModel.Channels { using System; using System.ServiceModel; using System.ServiceModel.Description; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Net.Security; using System.ServiceModel.Channels; public abstract class Binding : IDefaultCommunicationTimeouts { TimeSpan closeTimeout = ServiceDefaults.CloseTimeout; string name; string namespaceIdentifier; TimeSpan openTimeout = ServiceDefaults.OpenTimeout; TimeSpan receiveTimeout = ServiceDefaults.ReceiveTimeout; TimeSpan sendTimeout = ServiceDefaults.SendTimeout; internal const string DefaultNamespace = NamingHelper.DefaultNamespace; protected Binding() { this.name = null; this.namespaceIdentifier = DefaultNamespace; } protected Binding(string name, string ns) { if (string.IsNullOrEmpty(name)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("name", SR.GetString(SR.SFXBindingNameCannotBeNullOrEmpty)); } if (ns == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("ns"); } if (ns.Length > 0) { NamingHelper.CheckUriParameter(ns, "ns"); } this.name = name; this.namespaceIdentifier = ns; } public TimeSpan CloseTimeout { get { return this.closeTimeout; } set { if (value < TimeSpan.Zero) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value", value, SR.GetString(SR.SFxTimeoutOutOfRange0))); } if (TimeoutHelper.IsTooLarge(value)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value", value, SR.GetString(SR.SFxTimeoutOutOfRangeTooBig))); } this.closeTimeout = value; } } public string Name { get { if (this.name == null) this.name = this.GetType().Name; return this.name; } set { if (string.IsNullOrEmpty(value)) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("value", SR.GetString(SR.SFXBindingNameCannotBeNullOrEmpty)); this.name = value; } } public string Namespace { get { return this.namespaceIdentifier; } set { if (value == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("value"); } if (value.Length > 0) { NamingHelper.CheckUriProperty(value, "Namespace"); } this.namespaceIdentifier = value; } } public TimeSpan OpenTimeout { get { return this.openTimeout; } set { if (value < TimeSpan.Zero) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value", value, SR.GetString(SR.SFxTimeoutOutOfRange0))); } if (TimeoutHelper.IsTooLarge(value)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value", value, SR.GetString(SR.SFxTimeoutOutOfRangeTooBig))); } this.openTimeout = value; } } public TimeSpan ReceiveTimeout { get { return this.receiveTimeout; } set { if (value < TimeSpan.Zero) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value", value, SR.GetString(SR.SFxTimeoutOutOfRange0))); } if (TimeoutHelper.IsTooLarge(value)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value", value, SR.GetString(SR.SFxTimeoutOutOfRangeTooBig))); } this.receiveTimeout = value; } } public abstract string Scheme { get; } public MessageVersion MessageVersion { get { return this.GetProperty(new BindingParameterCollection()); } } public TimeSpan SendTimeout { get { return this.sendTimeout; } set { if (value < TimeSpan.Zero) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value", value, SR.GetString(SR.SFxTimeoutOutOfRange0))); } if (TimeoutHelper.IsTooLarge(value)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value", value, SR.GetString(SR.SFxTimeoutOutOfRangeTooBig))); } this.sendTimeout = value; } } public IChannelFactory BuildChannelFactory (params object[] parameters) { return this.BuildChannelFactory (new BindingParameterCollection(parameters)); } public virtual IChannelFactory BuildChannelFactory (BindingParameterCollection parameters) { EnsureInvariants(); BindingContext context = new BindingContext(new CustomBinding(this), parameters); IChannelFactory channelFactory = context.BuildInnerChannelFactory (); context.ValidateBindingElementsConsumed(); this.ValidateSecurityCapabilities(channelFactory.GetProperty (), parameters); return channelFactory; } void ValidateSecurityCapabilities(ISecurityCapabilities runtimeSecurityCapabilities, BindingParameterCollection parameters) { ISecurityCapabilities bindingSecurityCapabilities = this.GetProperty (parameters); if (!SecurityCapabilities.IsEqual(bindingSecurityCapabilities, runtimeSecurityCapabilities)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError( new InvalidOperationException(SR.GetString(SR.SecurityCapabilitiesMismatched, this))); } } public virtual IChannelListener BuildChannelListener (params object[] parameters) where TChannel : class, IChannel { return this.BuildChannelListener (new BindingParameterCollection(parameters)); } public virtual IChannelListener BuildChannelListener (Uri listenUriBaseAddress, params object[] parameters) where TChannel : class, IChannel { return this.BuildChannelListener (listenUriBaseAddress, new BindingParameterCollection(parameters)); } public virtual IChannelListener BuildChannelListener (Uri listenUriBaseAddress, string listenUriRelativeAddress, params object[] parameters) where TChannel : class, IChannel { return this.BuildChannelListener (listenUriBaseAddress, listenUriRelativeAddress, new BindingParameterCollection(parameters)); } public virtual IChannelListener BuildChannelListener (Uri listenUriBaseAddress, string listenUriRelativeAddress, ListenUriMode listenUriMode, params object[] parameters) where TChannel : class, IChannel { return this.BuildChannelListener (listenUriBaseAddress, listenUriRelativeAddress, listenUriMode, new BindingParameterCollection(parameters)); } public virtual IChannelListener BuildChannelListener (BindingParameterCollection parameters) where TChannel : class, IChannel { UriBuilder listenUriBuilder = new UriBuilder(this.Scheme, DnsCache.MachineName); return this.BuildChannelListener (listenUriBuilder.Uri, String.Empty, ListenUriMode.Unique, parameters); } public virtual IChannelListener BuildChannelListener (Uri listenUriBaseAddress, BindingParameterCollection parameters) where TChannel : class, IChannel { return this.BuildChannelListener (listenUriBaseAddress, String.Empty, ListenUriMode.Explicit, parameters); } public virtual IChannelListener BuildChannelListener (Uri listenUriBaseAddress, string listenUriRelativeAddress, BindingParameterCollection parameters) where TChannel : class, IChannel { return this.BuildChannelListener (listenUriBaseAddress, listenUriRelativeAddress, ListenUriMode.Explicit, parameters); } public virtual IChannelListener BuildChannelListener (Uri listenUriBaseAddress, string listenUriRelativeAddress, ListenUriMode listenUriMode, BindingParameterCollection parameters) where TChannel : class, IChannel { EnsureInvariants(); BindingContext context = new BindingContext(new CustomBinding(this), parameters, listenUriBaseAddress, listenUriRelativeAddress, listenUriMode); IChannelListener channelListener = context.BuildInnerChannelListener (); context.ValidateBindingElementsConsumed(); this.ValidateSecurityCapabilities(channelListener.GetProperty (), parameters); return channelListener; } public bool CanBuildChannelFactory (params object[] parameters) { return this.CanBuildChannelFactory (new BindingParameterCollection(parameters)); } public virtual bool CanBuildChannelFactory (BindingParameterCollection parameters) { BindingContext context = new BindingContext(new CustomBinding(this), parameters); return context.CanBuildInnerChannelFactory (); } public bool CanBuildChannelListener (params object[] parameters) where TChannel : class, IChannel { return this.CanBuildChannelListener (new BindingParameterCollection(parameters)); } public virtual bool CanBuildChannelListener (BindingParameterCollection parameters) where TChannel : class, IChannel { BindingContext context = new BindingContext(new CustomBinding(this), parameters); return context.CanBuildInnerChannelListener (); } // the elements should NOT reference internal elements used by the Binding public abstract BindingElementCollection CreateBindingElements(); public T GetProperty (BindingParameterCollection parameters) where T : class { BindingContext context = new BindingContext(new CustomBinding(this), parameters); return context.GetInnerProperty (); } void EnsureInvariants() { EnsureInvariants(null); } internal void EnsureInvariants(string contractName) { BindingElementCollection elements = this.CreateBindingElements(); TransportBindingElement transport = null; int index; for (index = 0; index < elements.Count; index++) { transport = elements[index] as TransportBindingElement; if (transport != null) break; } if (transport == null) { if (contractName == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException( SR.GetString(SR.CustomBindingRequiresTransport, this.Name))); } else { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException( SR.GetString(SR.SFxCustomBindingNeedsTransport1, contractName))); } } if (index != elements.Count - 1) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException( SR.GetString(SR.TransportBindingElementMustBeLast, this.Name, transport.GetType().Name))); } if (string.IsNullOrEmpty(transport.Scheme)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException( SR.GetString(SR.InvalidBindingScheme, transport.GetType().Name))); } if (this.MessageVersion == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException( SR.GetString(SR.MessageVersionMissingFromBinding, this.Name))); } } internal void CopyTimeouts(IDefaultCommunicationTimeouts source) { this.CloseTimeout = source.CloseTimeout; this.OpenTimeout = source.OpenTimeout; this.ReceiveTimeout = source.ReceiveTimeout; this.SendTimeout = source.SendTimeout; } } } // 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
- DropShadowBitmapEffect.cs
- MethodImplAttribute.cs
- StackOverflowException.cs
- TextRangeAdaptor.cs
- ApplicationServicesHostFactory.cs
- GeometryModel3D.cs
- MostlySingletonList.cs
- DefaultAssemblyResolver.cs
- LinkedResourceCollection.cs
- DataGridViewRowDividerDoubleClickEventArgs.cs
- UidManager.cs
- CompiledAction.cs
- EventLogEntry.cs
- ShimAsPublicXamlType.cs
- TraversalRequest.cs
- HyperLinkStyle.cs
- ErrorHandler.cs
- GridViewItemAutomationPeer.cs
- CheckBox.cs
- __FastResourceComparer.cs
- ObjectItemAssemblyLoader.cs
- DataBindingCollection.cs
- TypeGeneratedEventArgs.cs
- MSAANativeProvider.cs
- PropertyPathWorker.cs
- SHA512.cs
- AddInBase.cs
- ReflectionTypeLoadException.cs
- SqlUnionizer.cs
- InputMethod.cs
- Polygon.cs
- DragEventArgs.cs
- SemaphoreSecurity.cs
- WindowsListViewItemCheckBox.cs
- ping.cs
- UidPropertyAttribute.cs
- CounterSampleCalculator.cs
- DataGridCommandEventArgs.cs
- DocumentPageHost.cs
- SafePEFileHandle.cs
- GatewayIPAddressInformationCollection.cs
- ValidatingReaderNodeData.cs
- NativeMethods.cs
- DocumentPage.cs
- FlowDocumentFormatter.cs
- DockPanel.cs
- SessionStateSection.cs
- InputLanguageProfileNotifySink.cs
- LeftCellWrapper.cs
- DependencyObjectPropertyDescriptor.cs
- ExpandCollapsePattern.cs
- FormsAuthenticationCredentials.cs
- ContractInferenceHelper.cs
- Pointer.cs
- Expression.cs
- TextDocumentView.cs
- DrawingCollection.cs
- Currency.cs
- SmtpMail.cs
- SchemaElementLookUpTableEnumerator.cs
- AssemblyLoader.cs
- TreeViewBindingsEditorForm.cs
- DelegateOutArgument.cs
- Inflater.cs
- _SslSessionsCache.cs
- SafeNativeMethodsMilCoreApi.cs
- RunClient.cs
- DetailsViewRowCollection.cs
- SecurityPolicySection.cs
- SafeBitVector32.cs
- ObjectAssociationEndMapping.cs
- BrowserCapabilitiesCodeGenerator.cs
- Menu.cs
- PaintEvent.cs
- SiblingIterators.cs
- DrawingVisualDrawingContext.cs
- ServicePointManagerElement.cs
- GeometryHitTestParameters.cs
- QuotedPrintableStream.cs
- BindUriHelper.cs
- BamlTreeUpdater.cs
- OpenTypeCommon.cs
- HttpHandlerAction.cs
- FlowDocumentScrollViewer.cs
- AutoSizeToolBoxItem.cs
- ChannelServices.cs
- DBBindings.cs
- RectAnimationUsingKeyFrames.cs
- DatagridviewDisplayedBandsData.cs
- ObjectStateEntryOriginalDbUpdatableDataRecord.cs
- BitmapEffectInput.cs
- MetadataItem.cs
- BaseValidatorDesigner.cs
- TextEndOfLine.cs
- ConnectionProviderAttribute.cs
- BrowserCapabilitiesFactoryBase.cs
- WorkflowPageSetupDialog.cs
- InfiniteIntConverter.cs
- InvalidCastException.cs
- Adorner.cs