Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / System.ServiceModel.Discovery / System / ServiceModel / Discovery / Configuration / ConfigurationUtility.cs / 1305376 / ConfigurationUtility.cs
//----------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//---------------------------------------------------------------
namespace System.ServiceModel.Discovery.Configuration
{
using System.Configuration;
using System.Runtime;
using System.Security;
using System.ServiceModel.Configuration;
using System.ServiceModel.Description;
using SR2 = System.ServiceModel.Discovery.SR;
class ConfigurationUtility
{
public static ChannelEndpointElement GetDefaultDiscoveryEndpointElement()
{
return new ChannelEndpointElement() { Kind = ConfigurationStrings.UdpDiscoveryEndpoint };
}
public static T LookupEndpoint(ChannelEndpointElement channelEndpointElement) where T : ServiceEndpoint
{
Fx.Assert(channelEndpointElement != null, "The parameter channelEndpointElement must be non null.");
Fx.Assert(!string.IsNullOrEmpty(channelEndpointElement.Kind), "The Kind property of the specified channelEndpointElement parameter cannot be null or empty.");
return ConfigLoader.LookupEndpoint(channelEndpointElement, null) as T;
}
internal static void InitializeAndValidateUdpChannelEndpointElement(ChannelEndpointElement channelEndpointElement)
{
if (!String.IsNullOrEmpty(channelEndpointElement.Binding))
{
throw FxTrace.Exception.AsError(new ConfigurationErrorsException(SR2.DiscoveryConfigBindingSpecifiedForUdpDiscoveryEndpoint(channelEndpointElement.Kind)));;
}
if (!(channelEndpointElement.Address == null || String.IsNullOrEmpty(channelEndpointElement.Address.ToString())))
{
throw FxTrace.Exception.AsError(new ConfigurationErrorsException(SR2.DiscoveryConfigAddressSpecifiedForUdpDiscoveryEndpoint(channelEndpointElement.Kind)));
}
channelEndpointElement.Address = null;
}
internal static void InitializeAndValidateUdpServiceEndpointElement(ServiceEndpointElement serviceEndpointElement)
{
if (!String.IsNullOrEmpty(serviceEndpointElement.Binding))
{
throw FxTrace.Exception.AsError(new ConfigurationErrorsException(SR2.DiscoveryConfigBindingSpecifiedForUdpDiscoveryEndpoint(serviceEndpointElement.Kind)));;
}
if (!(serviceEndpointElement.Address == null || String.IsNullOrEmpty(serviceEndpointElement.Address.ToString())))
{
throw FxTrace.Exception.AsError(new ConfigurationErrorsException(SR2.DiscoveryConfigAddressSpecifiedForUdpDiscoveryEndpoint(serviceEndpointElement.Kind)));
}
serviceEndpointElement.Address = null;
if (serviceEndpointElement.ListenUri != null)
{
throw FxTrace.Exception.AsError(new ConfigurationErrorsException(SR2.DiscoveryConfigListenUriSpecifiedForUdpDiscoveryEndpoint(serviceEndpointElement.Kind)));
}
}
[Fx.Tag.SecurityNote(Critical = "it is calling the SecurityCritical method to load client configuration section",
Safe = "no configuration objects are leaked")]
[SecuritySafeCritical]
internal static TEndpoint LookupEndpointFromClientSection(string endpointConfigurationName) where TEndpoint : ServiceEndpoint
{
Fx.Assert(endpointConfigurationName != null, "The endpointConfigurationName parameter must be non null.");
TEndpoint retval = default(TEndpoint);
bool wildcard = string.Equals(endpointConfigurationName, "*", StringComparison.Ordinal);
ClientSection clientSection = ClientSection.GetSection();
foreach (ChannelEndpointElement channelEndpointElement in clientSection.Endpoints)
{
if (string.IsNullOrEmpty(channelEndpointElement.Kind))
{
continue;
}
if (endpointConfigurationName == channelEndpointElement.Name || wildcard)
{
TEndpoint endpoint = LookupEndpoint(channelEndpointElement);
if (endpoint != null)
{
if (retval != null)
{
if (wildcard)
{
throw FxTrace.Exception.AsError(
new InvalidOperationException(
SR2.DiscoveryConfigMultipleEndpointsMatchWildcard(
typeof(TEndpoint).FullName,
clientSection.SectionInformation.SectionName)));
}
else
{
throw FxTrace.Exception.AsError(
new InvalidOperationException(
SR2.DiscoveryConfigMultipleEndpointsMatch(
typeof(TEndpoint).FullName,
endpointConfigurationName,
clientSection.SectionInformation.SectionName)));
}
}
else
{
retval = endpoint;
}
}
}
}
if (retval == null)
{
if (wildcard)
{
throw FxTrace.Exception.AsError(
new InvalidOperationException(
SR2.DiscoveryConfigNoEndpointsMatchWildcard(
typeof(TEndpoint).FullName,
clientSection.SectionInformation.SectionName)));
}
else
{
throw FxTrace.Exception.AsError(
new InvalidOperationException(
SR2.DiscoveryConfigNoEndpointsMatch(
typeof(TEndpoint).FullName,
endpointConfigurationName,
clientSection.SectionInformation.SectionName)));
}
}
return retval;
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- DecoderBestFitFallback.cs
- InvokeProviderWrapper.cs
- AssertSection.cs
- FixedDocument.cs
- HwndSourceKeyboardInputSite.cs
- TrackingMemoryStreamFactory.cs
- Vector.cs
- PackWebResponse.cs
- EventLogPermissionAttribute.cs
- ChtmlLinkAdapter.cs
- QilNode.cs
- WindowsListViewItemCheckBox.cs
- SettingsPropertyNotFoundException.cs
- Point3D.cs
- CssStyleCollection.cs
- ChtmlFormAdapter.cs
- ExtenderHelpers.cs
- BitmapEffectOutputConnector.cs
- Splitter.cs
- ControlBuilder.cs
- FormatException.cs
- SdlChannelSink.cs
- OleDbErrorCollection.cs
- PeerNameRegistration.cs
- GrammarBuilderRuleRef.cs
- StatusBarPanel.cs
- XmlUrlEditor.cs
- XmlSerializationGeneratedCode.cs
- SingleObjectCollection.cs
- SafeRegistryKey.cs
- UpdatableWrapper.cs
- HeaderUtility.cs
- ChannelProtectionRequirements.cs
- SwitchElementsCollection.cs
- HttpSocketManager.cs
- FormClosingEvent.cs
- WebServiceClientProxyGenerator.cs
- MessagingActivityHelper.cs
- IfJoinedCondition.cs
- TrimSurroundingWhitespaceAttribute.cs
- RowSpanVector.cs
- SQLBinaryStorage.cs
- WebServiceHandler.cs
- Psha1DerivedKeyGeneratorHelper.cs
- ManagedIStream.cs
- AsyncCompletedEventArgs.cs
- RealizationContext.cs
- CriticalFinalizerObject.cs
- StringFreezingAttribute.cs
- EventListener.cs
- NameTable.cs
- DataGridViewCellCollection.cs
- X509ChainElement.cs
- ContainerParagraph.cs
- XmlSchemaNotation.cs
- Part.cs
- XmlDataSource.cs
- CompModSwitches.cs
- TimeStampChecker.cs
- FlowDocumentFormatter.cs
- BufferModesCollection.cs
- FigureHelper.cs
- XamlRtfConverter.cs
- CodeComment.cs
- xmlfixedPageInfo.cs
- HttpContextServiceHost.cs
- ChannelManager.cs
- BaseHashHelper.cs
- _CommandStream.cs
- SurrogateEncoder.cs
- CodeRemoveEventStatement.cs
- ServiceSecurityAuditElement.cs
- MouseGesture.cs
- CollectionMarkupSerializer.cs
- Sorting.cs
- SoapAttributes.cs
- CodeTypeDeclaration.cs
- SafeHandles.cs
- ListViewItemEventArgs.cs
- XmlExtensionFunction.cs
- SvcMapFileSerializer.cs
- RijndaelCryptoServiceProvider.cs
- SQLGuid.cs
- OciLobLocator.cs
- RemotingService.cs
- SchemaImporter.cs
- XmlTypeMapping.cs
- BamlTreeMap.cs
- ChannelServices.cs
- Metafile.cs
- Matrix.cs
- ValidationUtility.cs
- DrawingVisualDrawingContext.cs
- _NetRes.cs
- AttachedPropertyInfo.cs
- WebHttpElement.cs
- EncryptedPackage.cs
- TemplateControlParser.cs
- Stack.cs
- MemberPath.cs