Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / NetFx35 / System.ServiceModel.Web / System / ServiceModel / WebHttpBinding.cs / 1 / WebHttpBinding.cs
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------
namespace System.ServiceModel
{
using System;
using System.Configuration;
using System.ServiceModel.Channels;
using System.ServiceModel.Configuration;
using System.ServiceModel.Description;
using System.Text;
using System.Xml;
public class WebHttpBinding : Binding, IBindingRuntimePreferences
{
HttpsTransportBindingElement httpsTransportBindingElement;
// private BindingElements
HttpTransportBindingElement httpTransportBindingElement;
WebHttpSecurity security = new WebHttpSecurity();
WebMessageEncodingBindingElement webMessageEncodingBindingElement;
public WebHttpBinding() : this(WebHttpSecurityMode.None)
{
}
public WebHttpBinding(string configurationName) : this()
{
ApplyConfiguration(configurationName);
}
public WebHttpBinding(WebHttpSecurityMode securityMode) : base()
{
Initialize();
this.security.Mode = securityMode;
}
public bool AllowCookies
{
get { return httpTransportBindingElement.AllowCookies; }
set
{
httpTransportBindingElement.AllowCookies = value;
httpsTransportBindingElement.AllowCookies = value;
}
}
public bool BypassProxyOnLocal
{
get { return httpTransportBindingElement.BypassProxyOnLocal; }
set
{
httpTransportBindingElement.BypassProxyOnLocal = value;
httpsTransportBindingElement.BypassProxyOnLocal = value;
}
}
public EnvelopeVersion EnvelopeVersion
{
get { return EnvelopeVersion.None; }
}
public HostNameComparisonMode HostNameComparisonMode
{
get { return httpTransportBindingElement.HostNameComparisonMode; }
set
{
httpTransportBindingElement.HostNameComparisonMode = value;
httpsTransportBindingElement.HostNameComparisonMode = value;
}
}
public long MaxBufferPoolSize
{
get { return httpTransportBindingElement.MaxBufferPoolSize; }
set
{
httpTransportBindingElement.MaxBufferPoolSize = value;
httpsTransportBindingElement.MaxBufferPoolSize = value;
}
}
public int MaxBufferSize
{
get { return httpTransportBindingElement.MaxBufferSize; }
set
{
httpTransportBindingElement.MaxBufferSize = value;
httpsTransportBindingElement.MaxBufferSize = value;
}
}
public long MaxReceivedMessageSize
{
get { return httpTransportBindingElement.MaxReceivedMessageSize; }
set
{
httpTransportBindingElement.MaxReceivedMessageSize = value;
httpsTransportBindingElement.MaxReceivedMessageSize = value;
}
}
public Uri ProxyAddress
{
get { return httpTransportBindingElement.ProxyAddress; }
set
{
httpTransportBindingElement.ProxyAddress = value;
httpsTransportBindingElement.ProxyAddress = value;
}
}
public XmlDictionaryReaderQuotas ReaderQuotas
{
get { return webMessageEncodingBindingElement.ReaderQuotas; }
set
{
if (value == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("value");
}
value.CopyTo(webMessageEncodingBindingElement.ReaderQuotas);
}
}
public override string Scheme
{ get { return GetTransport().Scheme; } }
public WebHttpSecurity Security
{
get { return this.security; }
}
public TransferMode TransferMode
{
get { return httpTransportBindingElement.TransferMode; }
set
{
httpTransportBindingElement.TransferMode = value;
httpsTransportBindingElement.TransferMode = value;
}
}
public bool UseDefaultWebProxy
{
get { return httpTransportBindingElement.UseDefaultWebProxy; }
set
{
httpTransportBindingElement.UseDefaultWebProxy = value;
httpsTransportBindingElement.UseDefaultWebProxy = value;
}
}
public Encoding WriteEncoding
{
get { return webMessageEncodingBindingElement.WriteEncoding; }
set
{
webMessageEncodingBindingElement.WriteEncoding = value;
}
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1033:InterfaceMethodsShouldBeCallableByChildTypes")] // [....], This is the pattern we use on the standard bindings in Indigo V1
bool IBindingRuntimePreferences.ReceiveSynchronously
{
get { return false; }
}
public override BindingElementCollection CreateBindingElements()
{
// return collection of BindingElements
BindingElementCollection bindingElements = new BindingElementCollection();
// order of BindingElements is important
// add encoding
bindingElements.Add(webMessageEncodingBindingElement);
// add transport (http or https)
bindingElements.Add(GetTransport());
return bindingElements.Clone();
}
void ApplyConfiguration(string configurationName)
{
WebHttpBindingCollectionElement section = WebHttpBindingCollectionElement.GetBindingCollectionElement();
WebHttpBindingElement element = section.Bindings[configurationName];
if (element == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(
SR2.GetString(SR2.ConfigInvalidBindingConfigurationName,
configurationName,
WebHttpBindingConfigurationStrings.WebHttpBindingCollectionElementName)));
}
else
{
element.ApplyConfiguration(this);
}
}
TransportBindingElement GetTransport()
{
if (security.Mode == WebHttpSecurityMode.Transport)
{
security.EnableTransportSecurity(httpsTransportBindingElement);
return httpsTransportBindingElement;
}
else if (security.Mode == WebHttpSecurityMode.TransportCredentialOnly)
{
security.EnableTransportAuthentication(httpTransportBindingElement);
return httpTransportBindingElement;
}
else
{
// ensure that there is no transport security
security.DisableTransportAuthentication(httpTransportBindingElement);
return httpTransportBindingElement;
}
}
void Initialize()
{
httpTransportBindingElement = new HttpTransportBindingElement();
httpsTransportBindingElement = new HttpsTransportBindingElement();
httpTransportBindingElement.ManualAddressing = true;
httpsTransportBindingElement.ManualAddressing = true;
webMessageEncodingBindingElement = new WebMessageEncodingBindingElement();
webMessageEncodingBindingElement.MessageVersion = MessageVersion.None;
}
internal static class WebHttpBindingConfigurationStrings
{
internal const string WebHttpBindingCollectionElementName = "webHttpBinding";
}
}
}
// 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
- SafeProcessHandle.cs
- DataGridItemCollection.cs
- ComponentEditorPage.cs
- CodeAccessPermission.cs
- DataGridViewToolTip.cs
- CodeStatementCollection.cs
- ManagedWndProcTracker.cs
- DataTableMapping.cs
- XmlDownloadManager.cs
- RootBuilder.cs
- UnitySerializationHolder.cs
- CheckBoxRenderer.cs
- ButtonChrome.cs
- ListItemsCollectionEditor.cs
- DefinitionUpdate.cs
- GcSettings.cs
- SrgsSubset.cs
- FileSystemInfo.cs
- ActivitySurrogateSelector.cs
- DependencyPropertyKind.cs
- ColumnTypeConverter.cs
- ToolboxItemSnapLineBehavior.cs
- ScrollItemPattern.cs
- ToolStripContainerDesigner.cs
- GroupBoxRenderer.cs
- AttributeInfo.cs
- AssemblyName.cs
- wgx_render.cs
- DocComment.cs
- QueuePropertyVariants.cs
- SequenceDesigner.cs
- TemplateBindingExpressionConverter.cs
- SupportsEventValidationAttribute.cs
- WindowsIPAddress.cs
- DesignerActionHeaderItem.cs
- SizeIndependentAnimationStorage.cs
- TransactionBehavior.cs
- ObsoleteAttribute.cs
- ButtonBase.cs
- HttpModulesSection.cs
- DesignerMetadata.cs
- CodeSubDirectory.cs
- XmlSchemaSimpleTypeUnion.cs
- SingleAnimation.cs
- _AuthenticationState.cs
- ZipPackagePart.cs
- BaseParser.cs
- FixedSOMTableCell.cs
- HuffModule.cs
- Win32Native.cs
- SatelliteContractVersionAttribute.cs
- SizeAnimationClockResource.cs
- EmulateRecognizeCompletedEventArgs.cs
- GeneralTransform3DGroup.cs
- ISSmlParser.cs
- DataControlExtensions.cs
- ObjectStateEntryDbUpdatableDataRecord.cs
- UnsafeCollabNativeMethods.cs
- ValueQuery.cs
- ConfigurationErrorsException.cs
- wgx_render.cs
- ScriptComponentDescriptor.cs
- InternalControlCollection.cs
- DataSourceCache.cs
- XmlAutoDetectWriter.cs
- Sql8ExpressionRewriter.cs
- UnsafeNativeMethods.cs
- RemoteDebugger.cs
- DataSource.cs
- ResourceCodeDomSerializer.cs
- propertyentry.cs
- SoapInteropTypes.cs
- KeyFrames.cs
- AsymmetricCryptoHandle.cs
- XmlSerializationReader.cs
- FrameworkElementAutomationPeer.cs
- IdnMapping.cs
- UnknownExceptionActionHelper.cs
- StopStoryboard.cs
- XmlNamedNodeMap.cs
- MissingSatelliteAssemblyException.cs
- filewebrequest.cs
- PageTheme.cs
- SoapExtensionTypeElementCollection.cs
- FamilyTypefaceCollection.cs
- Tile.cs
- ConcurrentQueue.cs
- ListChunk.cs
- Collection.cs
- ResourceType.cs
- Package.cs
- StorageTypeMapping.cs
- WeakReference.cs
- HandledMouseEvent.cs
- UrlMappingCollection.cs
- PeerNameRecord.cs
- SqlUDTStorage.cs
- _StreamFramer.cs
- WebZone.cs
- BulletedListDesigner.cs