Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Description / MetadataExchangeBindings.cs / 1 / MetadataExchangeBindings.cs
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------
namespace System.ServiceModel.Description
{
using System.Globalization;
using System.ServiceModel.Channels;
using System.ServiceModel;
using System.Collections.Generic;
public static class MetadataExchangeBindings
{
static Binding httpBinding;
static Binding httpGetBinding;
static Binding httpsBinding;
static Binding httpsGetBinding;
static Binding tcpBinding;
static Binding pipeBinding;
internal static Binding Http
{
get
{
// don't need to lock because no guarantee of instance identity
if (httpBinding == null)
{
httpBinding = CreateHttpBinding();
}
return httpBinding;
}
}
internal static Binding HttpGet
{
get
{
// don't need to lock because no guarantee of instance identity
if (httpGetBinding == null)
{
httpGetBinding = CreateHttpGetBinding();
}
return httpGetBinding;
}
}
internal static Binding Https
{
get
{
// don't need to lock because no guarantee of instance identity
if (httpsBinding == null)
{
httpsBinding = CreateHttpsBinding();
}
return httpsBinding;
}
}
internal static Binding HttpsGet
{
get
{
// don't need to lock because no guarantee of instance identity
if (httpsGetBinding == null)
{
httpsGetBinding = CreateHttpsGetBinding();
}
return httpsGetBinding;
}
}
internal static Binding Tcp
{
get
{
// don't need to lock because no guarantee of instance identity
if (tcpBinding == null)
{
tcpBinding = CreateTcpBinding();
}
return tcpBinding;
}
}
internal static Binding NamedPipe
{
get
{
// don't need to lock because no guarantee of instance identity
if (pipeBinding == null)
{
pipeBinding = CreateNamedPipeBinding();
}
return pipeBinding;
}
}
public static Binding CreateMexHttpBinding()
{
return MetadataExchangeBindings.CreateHttpBinding();
}
public static Binding CreateMexHttpsBinding()
{
return MetadataExchangeBindings.CreateHttpsBinding();
}
public static Binding CreateMexTcpBinding()
{
return MetadataExchangeBindings.CreateTcpBinding();
}
public static Binding CreateMexNamedPipeBinding()
{
return MetadataExchangeBindings.CreateNamedPipeBinding();
}
internal static Binding GetBindingForScheme(string scheme)
{
Binding binding = null;
TryGetBindingForScheme(scheme, out binding);
return binding;
}
internal static bool TryGetBindingForScheme(string scheme, out Binding binding)
{
if (String.Compare(scheme, "http", StringComparison.OrdinalIgnoreCase) == 0)
{
binding = Http;
}
else if (String.Compare(scheme, "https", StringComparison.OrdinalIgnoreCase) == 0)
{
binding = Https;
}
else if (String.Compare(scheme, "net.tcp", StringComparison.OrdinalIgnoreCase) == 0)
{
binding = Tcp;
}
else if (String.Compare(scheme, "net.pipe", StringComparison.OrdinalIgnoreCase) == 0)
{
binding = NamedPipe;
}
else
{
binding = null;
}
return binding != null;
}
static WSHttpBinding CreateHttpBinding()
{
WSHttpBinding binding = new WSHttpBinding(SecurityMode.None, /* reliableSessionEnabled */ false);
binding.Name = MetadataStrings.MetadataExchangeStrings.HttpBindingName;
binding.Namespace = MetadataStrings.MetadataExchangeStrings.BindingNamespace;
return binding;
}
static WSHttpBinding CreateHttpsBinding()
{
WSHttpBinding binding = new WSHttpBinding(
new WSHttpSecurity(SecurityMode.Transport, new HttpTransportSecurity(), new NonDualMessageSecurityOverHttp()), /* reliableSessionEnabled */ false);
binding.Name = MetadataStrings.MetadataExchangeStrings.HttpsBindingName;
binding.Namespace = MetadataStrings.MetadataExchangeStrings.BindingNamespace;
return binding;
}
static CustomBinding CreateHttpGetBinding()
{
return CreateGetBinding(new HttpTransportBindingElement());
}
static CustomBinding CreateHttpsGetBinding()
{
return CreateGetBinding(new HttpsTransportBindingElement());
}
static CustomBinding CreateGetBinding(HttpTransportBindingElement httpTransport)
{
TextMessageEncodingBindingElement textEncoding = new TextMessageEncodingBindingElement();
textEncoding.MessageVersion = MessageVersion.None;
httpTransport.Method = "GET";
httpTransport.InheritBaseAddressSettings = true;
return new CustomBinding(textEncoding, httpTransport);
}
static CustomBinding CreateTcpBinding()
{
CustomBinding binding = new CustomBinding(MetadataStrings.MetadataExchangeStrings.TcpBindingName, MetadataStrings.MetadataExchangeStrings.BindingNamespace);
TcpTransportBindingElement tcpTransport = new TcpTransportBindingElement();
binding.Elements.Add(tcpTransport);
return binding;
}
static CustomBinding CreateNamedPipeBinding()
{
CustomBinding binding = new CustomBinding(MetadataStrings.MetadataExchangeStrings.NamedPipeBindingName, MetadataStrings.MetadataExchangeStrings.BindingNamespace);
NamedPipeTransportBindingElement pipeTransport = new NamedPipeTransportBindingElement();
binding.Elements.Add(pipeTransport);
return binding;
}
internal static bool IsSchemeSupported(string scheme)
{
Binding binding;
return TryGetBindingForScheme(scheme, out binding);
}
}
}
// 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
- XmlDataCollection.cs
- NTAccount.cs
- TypeReference.cs
- SchemaCollectionPreprocessor.cs
- ProcessHostFactoryHelper.cs
- TemplateGroupCollection.cs
- CompositionAdorner.cs
- AddingNewEventArgs.cs
- DiffuseMaterial.cs
- KeyValueSerializer.cs
- _WebProxyDataBuilder.cs
- TemplateComponentConnector.cs
- BaseValidator.cs
- CuspData.cs
- ScrollableControl.cs
- MessageDecoder.cs
- ToolStripLocationCancelEventArgs.cs
- ObjectComplexPropertyMapping.cs
- RegexReplacement.cs
- DelayLoadType.cs
- ObjectDataSourceStatusEventArgs.cs
- ImageField.cs
- MouseEvent.cs
- RowToParametersTransformer.cs
- KernelTypeValidation.cs
- CodeExporter.cs
- DataSourceCache.cs
- Typography.cs
- IEnumerable.cs
- ToolStripDropDownMenu.cs
- CompressionTransform.cs
- KeyGestureConverter.cs
- AssemblySettingAttributes.cs
- EmissiveMaterial.cs
- SkewTransform.cs
- ParallelForEach.cs
- FlowDocument.cs
- AssemblyCollection.cs
- GenericIdentity.cs
- EventLogPermissionAttribute.cs
- TextPattern.cs
- OleCmdHelper.cs
- RunWorkerCompletedEventArgs.cs
- SymbolMethod.cs
- GenerateDerivedKeyRequest.cs
- ReadOnlyHierarchicalDataSource.cs
- HashStream.cs
- WorkItem.cs
- CursorEditor.cs
- BeginStoryboard.cs
- SchemaNames.cs
- coordinatorscratchpad.cs
- SizeConverter.cs
- ResourceProviderFactory.cs
- MimeTypeMapper.cs
- EventSinkActivityDesigner.cs
- SqlFileStream.cs
- SByte.cs
- MulticastDelegate.cs
- SharedConnectionListener.cs
- UMPAttributes.cs
- PrePrepareMethodAttribute.cs
- SafeRightsManagementHandle.cs
- InputScopeConverter.cs
- HtmlInputFile.cs
- ListViewPagedDataSource.cs
- ToolStripContentPanelRenderEventArgs.cs
- dataSvcMapFileLoader.cs
- ValueExpressions.cs
- AssertUtility.cs
- SafeLibraryHandle.cs
- XmlDataSourceNodeDescriptor.cs
- X509Utils.cs
- ToolStripRenderer.cs
- ResolveMatchesMessage11.cs
- LocationFactory.cs
- MenuItem.cs
- ZipFileInfoCollection.cs
- StateBag.cs
- ImageInfo.cs
- ObjectMemberMapping.cs
- ValueExpressions.cs
- ResourceDescriptionAttribute.cs
- BooleanExpr.cs
- Missing.cs
- CompModSwitches.cs
- RectKeyFrameCollection.cs
- HttpModuleCollection.cs
- RtfToken.cs
- FixedTextView.cs
- MachineSettingsSection.cs
- ContextMenuStrip.cs
- HostUtils.cs
- TableItemStyle.cs
- FlowSwitchLink.cs
- OrderedDictionaryStateHelper.cs
- ServiceCredentialsElement.cs
- Help.cs
- RecipientServiceModelSecurityTokenRequirement.cs
- Vector3DValueSerializer.cs