Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Channels / BindingContext.cs / 1 / BindingContext.cs
//------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace System.ServiceModel.Channels
{
using System.ServiceModel.Description;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Globalization;
using System.Text;
public class BindingContext
{
CustomBinding binding;
BindingParameterCollection bindingParameters;
Uri listenUriBaseAddress;
ListenUriMode listenUriMode;
string listenUriRelativeAddress;
BindingElementCollection remainingBindingElements; // kept to ensure each BE builds itself once
public BindingContext(CustomBinding binding, BindingParameterCollection parameters)
: this(binding, parameters, null, string.Empty, ListenUriMode.Explicit)
{
}
public BindingContext(CustomBinding binding, BindingParameterCollection parameters, Uri listenUriBaseAddress, string listenUriRelativeAddress, ListenUriMode listenUriMode)
{
if (binding == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("binding");
}
if (listenUriRelativeAddress == null)
{
listenUriRelativeAddress = string.Empty;
}
if (!ListenUriModeHelper.IsDefined(listenUriMode))
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("listenUriMode"));
}
Initialize(binding, binding.Elements, parameters, listenUriBaseAddress, listenUriRelativeAddress, listenUriMode);
}
BindingContext(CustomBinding binding,
BindingElementCollection remainingBindingElements,
BindingParameterCollection parameters,
Uri listenUriBaseAddress,
string listenUriRelativeAddress,
ListenUriMode listenUriMode)
{
Initialize(binding, remainingBindingElements, parameters, listenUriBaseAddress, listenUriRelativeAddress, listenUriMode);
}
void Initialize(CustomBinding binding,
BindingElementCollection remainingBindingElements,
BindingParameterCollection parameters,
Uri listenUriBaseAddress,
string listenUriRelativeAddress,
ListenUriMode listenUriMode)
{
this.binding = binding;
this.remainingBindingElements = new BindingElementCollection(remainingBindingElements);
this.bindingParameters = new BindingParameterCollection(parameters);
this.listenUriBaseAddress = listenUriBaseAddress;
this.listenUriRelativeAddress = listenUriRelativeAddress;
this.listenUriMode = listenUriMode;
}
public CustomBinding Binding
{
get { return this.binding; }
}
public BindingParameterCollection BindingParameters
{
get { return this.bindingParameters; }
}
public Uri ListenUriBaseAddress
{
get { return this.listenUriBaseAddress; }
set { this.listenUriBaseAddress = value; }
}
public ListenUriMode ListenUriMode
{
get { return this.listenUriMode; }
set { this.listenUriMode = value; }
}
public string ListenUriRelativeAddress
{
get { return this.listenUriRelativeAddress; }
set { this.listenUriRelativeAddress = value; }
}
public BindingElementCollection RemainingBindingElements
{
get { return this.remainingBindingElements; }
}
public IChannelFactory BuildInnerChannelFactory()
{
return this.RemoveNextElement().BuildChannelFactory(this);
}
public IChannelListener BuildInnerChannelListener()
where TChannel : class, IChannel
{
return this.RemoveNextElement().BuildChannelListener(this);
}
public bool CanBuildInnerChannelFactory()
{
BindingContext clone = this.Clone();
return clone.RemoveNextElement().CanBuildChannelFactory(clone);
}
public bool CanBuildInnerChannelListener()
where TChannel : class, IChannel
{
BindingContext clone = this.Clone();
return clone.RemoveNextElement().CanBuildChannelListener(clone);
}
public T GetInnerProperty()
where T : class
{
if (this.remainingBindingElements.Count == 0)
{
return null;
}
else
{
BindingContext clone = this.Clone();
return clone.RemoveNextElement().GetProperty(clone);
}
}
public BindingContext Clone()
{
return new BindingContext(this.binding, this.remainingBindingElements, this.bindingParameters,
this.listenUriBaseAddress, this.listenUriRelativeAddress, this.listenUriMode);
}
BindingElement RemoveNextElement()
{
BindingElement element = this.remainingBindingElements.Remove();
if (element != null)
return element;
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(
SR.NoChannelBuilderAvailable, this.binding.Name, this.binding.Namespace)));
}
internal void ValidateBindingElementsConsumed()
{
if (this.RemainingBindingElements.Count != 0)
{
StringBuilder builder = new StringBuilder();
foreach (BindingElement bindingElement in this.RemainingBindingElements)
{
if (builder.Length > 0)
{
builder.Append(CultureInfo.CurrentCulture.TextInfo.ListSeparator);
builder.Append(" ");
}
string typeString = bindingElement.GetType().ToString();
builder.Append(typeString.Substring(typeString.LastIndexOf('.') + 1));
}
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.NotAllBindingElementsBuilt, builder.ToString())));
}
}
}
}
// 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
- ConfigXmlComment.cs
- securitycriticaldata.cs
- RequestResponse.cs
- XmlSchemaRedefine.cs
- HttpWebResponse.cs
- ClockController.cs
- PasswordBox.cs
- ProxyAttribute.cs
- BitConverter.cs
- DBDataPermission.cs
- CodeMemberField.cs
- BamlMapTable.cs
- DataGridViewColumn.cs
- OleServicesContext.cs
- LinqDataSourceDeleteEventArgs.cs
- StackOverflowException.cs
- ChildDocumentBlock.cs
- CipherData.cs
- ServiceAuthorizationManager.cs
- AuthenticationConfig.cs
- ErrorTableItemStyle.cs
- CountAggregationOperator.cs
- EventLogPermissionEntry.cs
- TdsParserHelperClasses.cs
- SQLDoubleStorage.cs
- EntityDataSourceMemberPath.cs
- GroupStyle.cs
- ArrayHelper.cs
- WeakEventManager.cs
- ConfigXmlWhitespace.cs
- ToolStripDropDownClosedEventArgs.cs
- ScriptControl.cs
- SqlClientWrapperSmiStreamChars.cs
- RemoteWebConfigurationHostStream.cs
- SqlCommandAsyncResult.cs
- LineServicesCallbacks.cs
- StylusOverProperty.cs
- MissingFieldException.cs
- IndexingContentUnit.cs
- ItemsPanelTemplate.cs
- FormViewModeEventArgs.cs
- CustomErrorCollection.cs
- FixedFindEngine.cs
- MetadataUtilsSmi.cs
- RIPEMD160.cs
- ColorDialog.cs
- RoutedPropertyChangedEventArgs.cs
- GridEntryCollection.cs
- PersonalizablePropertyEntry.cs
- StringCollection.cs
- DashStyles.cs
- HotCommands.cs
- HtmlHead.cs
- RectConverter.cs
- TextTreeRootTextBlock.cs
- EntityClassGenerator.cs
- SmtpLoginAuthenticationModule.cs
- UInt16Storage.cs
- XmlHierarchyData.cs
- HttpModuleActionCollection.cs
- SqlCaseSimplifier.cs
- TextEndOfParagraph.cs
- Stopwatch.cs
- CodeExporter.cs
- BitStack.cs
- CategoryNameCollection.cs
- TraceSection.cs
- XmlRawWriter.cs
- ValidationSummary.cs
- UserControlAutomationPeer.cs
- DescriptionAttribute.cs
- LinqDataSource.cs
- TlsnegoTokenProvider.cs
- ShaderEffect.cs
- AssociationSetMetadata.cs
- LogWriteRestartAreaState.cs
- DBConnectionString.cs
- ISO2022Encoding.cs
- TcpConnectionPool.cs
- GridSplitterAutomationPeer.cs
- ResourceReader.cs
- UpdatePanelTriggerCollection.cs
- ResourceReferenceExpression.cs
- BrowsableAttribute.cs
- StateDesigner.TransitionInfo.cs
- DataGridPreparingCellForEditEventArgs.cs
- KeyboardEventArgs.cs
- UICuesEvent.cs
- XmlReflectionImporter.cs
- FontCollection.cs
- ParameterBuilder.cs
- MouseActionValueSerializer.cs
- RewritingProcessor.cs
- ProxyElement.cs
- Constraint.cs
- EditorPartCollection.cs
- BrowserTree.cs
- ChannelServices.cs
- TouchEventArgs.cs
- BuildProvidersCompiler.cs