Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Description / ConfigWriter.cs / 1 / ConfigWriter.cs
//------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace System.ServiceModel.Description
{
using System;
using System.ServiceModel.Channels;
using System.Configuration;
using System.Collections.Generic;
using System.ServiceModel;
using System.ServiceModel.Configuration;
using System.ServiceModel.Diagnostics;
internal class ConfigWriter
{
readonly Dictionary bindingTable;
readonly BindingsSection bindingsSection;
readonly ChannelEndpointElementCollection channels;
readonly Configuration config;
internal ConfigWriter(Configuration configuration)
{
this.bindingTable = new Dictionary();
this.bindingsSection = BindingsSection.GetSection(configuration);
ServiceModelSectionGroup serviceModelSectionGroup = ServiceModelSectionGroup.GetSectionGroup(configuration);
this.channels = serviceModelSectionGroup.Client.Endpoints;
this.config = configuration;
}
internal ChannelEndpointElement WriteChannelDescription(ServiceEndpoint endpoint, string typeName)
{
ChannelEndpointElement channelElement = null;
// Create Binding
BindingDictionaryValue bindingDV = CreateBindingConfig(endpoint.Binding);
channelElement = new ChannelEndpointElement(endpoint.Address, typeName);
// [....]: review: Use decoded form to preserve the user-given friendly name, however, beacuse our Encoding algorithm
// does not touch ASCII names, a name that looks like encoded name will not roundtrip(Example: "_x002C_" will turned into ",")
channelElement.Name = NamingHelper.GetUniqueName(NamingHelper.CodeName(endpoint.Name), this.CheckIfChannelNameInUse, null);
channelElement.BindingConfiguration = bindingDV.BindingName;
channelElement.Binding = bindingDV.BindingSectionName;
channels.Add(channelElement);
return channelElement;
}
internal void WriteBinding(Binding binding, out string bindingSectionName, out string configurationName)
{
BindingDictionaryValue result = CreateBindingConfig(binding);
configurationName = result.BindingName;
bindingSectionName = result.BindingSectionName;
}
BindingDictionaryValue CreateBindingConfig(Binding binding)
{
BindingDictionaryValue bindingDV;
if (!bindingTable.TryGetValue(binding, out bindingDV))
{
// [....]: review: Use decoded form to preserve the user-given friendly name, however, beacuse our Encoding algorithm
// does not touch ASCII names, a name that looks like encoded name will not roundtrip(Example: "_x002C_" will turned into ",")
string bindingName = NamingHelper.GetUniqueName(NamingHelper.CodeName(binding.Name), this.CheckIfBindingNameInUse, null);
string bindingSectionName;
if (!BindingsSection.TryAdd(bindingName, binding, config, out bindingSectionName))
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.GetString(SR.ConfigBindingCannotBeConfigured), "endpoint.Binding"));
bindingDV = new BindingDictionaryValue(bindingName, bindingSectionName);
bindingTable.Add(binding, bindingDV);
}
return bindingDV;
}
bool CheckIfBindingNameInUse(string name, object nameCollection)
{
foreach (BindingCollectionElement bindingCollectionElement in this.bindingsSection.BindingCollections)
if (bindingCollectionElement.ContainsKey(name))
return true;
return false;
}
bool CheckIfChannelNameInUse(string name, object namingCollection)
{
foreach (ChannelEndpointElement element in this.channels)
if (element.Name == name)
return true;
return false;
}
sealed class BindingDictionaryValue
{
public readonly string BindingName;
public readonly string BindingSectionName;
public BindingDictionaryValue(string bindingName, string bindingSectionName)
{
this.BindingName = bindingName;
this.BindingSectionName = bindingSectionName;
}
}
}
}
// 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
- Char.cs
- Selection.cs
- DataKey.cs
- XmlCharCheckingReader.cs
- EntityClientCacheEntry.cs
- ScalarConstant.cs
- EventSourceCreationData.cs
- InlineObject.cs
- NetCodeGroup.cs
- EntityTemplateFactory.cs
- Cursor.cs
- HostedAspNetEnvironment.cs
- ObjectDataSourceChooseTypePanel.cs
- AssemblyAttributes.cs
- ControlValuePropertyAttribute.cs
- Part.cs
- Emitter.cs
- InteropAutomationProvider.cs
- TransformGroup.cs
- ResourceManager.cs
- DataServiceQueryOfT.cs
- Directory.cs
- AuthenticationModuleElementCollection.cs
- XmlSchemaFacet.cs
- Missing.cs
- DrawingDrawingContext.cs
- CompositeFontInfo.cs
- SQLBoolean.cs
- FlowDecisionDesigner.xaml.cs
- EdgeProfileValidation.cs
- TypeLibConverter.cs
- SchemaHelper.cs
- QueryExtender.cs
- ServiceObjectContainer.cs
- GuidTagList.cs
- CompensationHandlingFilter.cs
- Vector3DCollection.cs
- _BaseOverlappedAsyncResult.cs
- TimeEnumHelper.cs
- SyndicationDeserializer.cs
- BitmapEffectDrawingContextState.cs
- BitmapEffectGroup.cs
- BCryptSafeHandles.cs
- PropertyMetadata.cs
- AttributeQuery.cs
- MSAAEventDispatcher.cs
- TextEndOfLine.cs
- StylusCaptureWithinProperty.cs
- DataKeyCollection.cs
- IndentTextWriter.cs
- DataListItemCollection.cs
- ConfigXmlCDataSection.cs
- TypeSemantics.cs
- MenuRenderer.cs
- ProxyWebPart.cs
- ListItemCollection.cs
- SetterBaseCollection.cs
- LabelAutomationPeer.cs
- MarkupObject.cs
- DataGridViewRowStateChangedEventArgs.cs
- WpfXamlLoader.cs
- TransactionProxy.cs
- DataGridViewRowContextMenuStripNeededEventArgs.cs
- TcpProcessProtocolHandler.cs
- ArgumentOutOfRangeException.cs
- WebPartZoneCollection.cs
- SHA384Cng.cs
- AutomationElement.cs
- FileRecordSequence.cs
- SignatureToken.cs
- NullableDoubleAverageAggregationOperator.cs
- PowerStatus.cs
- CallId.cs
- DataControlImageButton.cs
- BooleanStorage.cs
- XpsS0ValidatingLoader.cs
- ToolStripProgressBar.cs
- TextSimpleMarkerProperties.cs
- SubpageParaClient.cs
- GetRecipientRequest.cs
- PopupRootAutomationPeer.cs
- Themes.cs
- RowsCopiedEventArgs.cs
- EntityDataSourceUtil.cs
- GradientPanel.cs
- InfoCardArgumentException.cs
- ToolStripDropDownMenu.cs
- RuleSettings.cs
- ComponentDesigner.cs
- HttpTransportManager.cs
- ValidationHelper.cs
- FamilyMapCollection.cs
- QueryExpr.cs
- JapaneseCalendar.cs
- OrderingQueryOperator.cs
- TypeSource.cs
- MarshalByRefObject.cs
- Context.cs
- Highlights.cs
- DataServiceKeyAttribute.cs