Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Channels / MtomMessageEncodingBindingElement.cs / 1 / MtomMessageEncodingBindingElement.cs
//------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.ServiceModel.Channels { using System.Collections.Generic; using System.ServiceModel.Description; using System.Runtime.Serialization; using System.ServiceModel.Channels; using System.ServiceModel; using System.Text; using System.Xml; public sealed class MtomMessageEncodingBindingElement : MessageEncodingBindingElement, IWsdlExportExtension, IPolicyExportExtension { int maxReadPoolSize; int maxWritePoolSize; XmlDictionaryReaderQuotas readerQuotas; int maxBufferSize; Encoding writeEncoding; MessageVersion messageVersion; public MtomMessageEncodingBindingElement() : this(MessageVersion.Default, TextEncoderDefaults.Encoding) { } public MtomMessageEncodingBindingElement(MessageVersion messageVersion, Encoding writeEncoding) { if (messageVersion == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("messageVersion"); if (messageVersion == MessageVersion.None) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.GetString(SR.MtomEncoderBadMessageVersion, messageVersion.ToString()), "messageVersion")); if (writeEncoding == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("writeEncoding"); TextEncoderDefaults.ValidateEncoding(writeEncoding); this.maxReadPoolSize = EncoderDefaults.MaxReadPoolSize; this.maxWritePoolSize = EncoderDefaults.MaxWritePoolSize; this.readerQuotas = new XmlDictionaryReaderQuotas(); EncoderDefaults.ReaderQuotas.CopyTo(this.readerQuotas); this.maxBufferSize = MtomEncoderDefaults.MaxBufferSize; this.messageVersion = messageVersion; this.writeEncoding = writeEncoding; } MtomMessageEncodingBindingElement(MtomMessageEncodingBindingElement elementToBeCloned) : base(elementToBeCloned) { this.maxReadPoolSize = elementToBeCloned.maxReadPoolSize; this.maxWritePoolSize = elementToBeCloned.maxWritePoolSize; this.readerQuotas = new XmlDictionaryReaderQuotas(); elementToBeCloned.readerQuotas.CopyTo(this.readerQuotas); this.maxBufferSize = elementToBeCloned.maxBufferSize; this.writeEncoding = elementToBeCloned.writeEncoding; this.messageVersion = elementToBeCloned.messageVersion; } public int MaxReadPoolSize { get { return this.maxReadPoolSize; } set { if (value <= 0) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value", value, SR.GetString(SR.ValueMustBePositive))); } this.maxReadPoolSize = value; } } public int MaxWritePoolSize { get { return this.maxWritePoolSize; } set { if (value <= 0) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value", value, SR.GetString(SR.ValueMustBePositive))); } this.maxWritePoolSize = value; } } public XmlDictionaryReaderQuotas ReaderQuotas { get { return this.readerQuotas; } } public int MaxBufferSize { get { return this.maxBufferSize; } set { if (value <= 0) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value", value, SR.GetString(SR.ValueMustBePositive))); } this.maxBufferSize = value; } } public Encoding WriteEncoding { get { return this.writeEncoding; } set { if (value == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("value"); TextEncoderDefaults.ValidateEncoding(value); this.writeEncoding = value; } } public override MessageVersion MessageVersion { get { return this.messageVersion; } set { if (value == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("value"); } if (value == MessageVersion.None) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.GetString(SR.MtomEncoderBadMessageVersion, value.ToString()), "value")); } this.messageVersion = value; } } public override IChannelFactoryBuildChannelFactory (BindingContext context) { return InternalBuildChannelFactory (context); } public override bool CanBuildChannelFactory (BindingContext context) { return InternalCanBuildChannelFactory (context); } public override IChannelListener BuildChannelListener (BindingContext context) { return InternalBuildChannelListener (context); } public override bool CanBuildChannelListener (BindingContext context) { return InternalCanBuildChannelListener (context); } public override BindingElement Clone() { return new MtomMessageEncodingBindingElement(this); } public override MessageEncoderFactory CreateMessageEncoderFactory() { return new MtomMessageEncoderFactory(MessageVersion, WriteEncoding, this.MaxReadPoolSize, this.MaxWritePoolSize, this.MaxBufferSize, this.ReaderQuotas); } public override T GetProperty (BindingContext context) { if (context == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context"); } if (typeof(T) == typeof(XmlDictionaryReaderQuotas)) { return (T)(object)this.readerQuotas; } else { return base.GetProperty (context); } } void IPolicyExportExtension.ExportPolicy(MetadataExporter exporter, PolicyConversionContext policyContext) { if (policyContext == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("policyContext"); } XmlDocument document = new XmlDocument(); policyContext.GetBindingAssertions().Add(document.CreateElement( MessageEncodingPolicyConstants.OptimizedMimeSerializationPrefix, MessageEncodingPolicyConstants.MtomEncodingName, MessageEncodingPolicyConstants.OptimizedMimeSerializationNamespace)); } void IWsdlExportExtension.ExportContract(WsdlExporter exporter, WsdlContractConversionContext context) { } void IWsdlExportExtension.ExportEndpoint(WsdlExporter exporter, WsdlEndpointConversionContext context) { if (context == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context"); } SoapHelper.SetSoapVersion(context, exporter, this.messageVersion.Envelope); } internal override bool CheckEncodingVersion(EnvelopeVersion version) { return messageVersion.Envelope == version; } internal override bool IsMatch(BindingElement b) { if (!base.IsMatch(b)) return false; MtomMessageEncodingBindingElement mtom = b as MtomMessageEncodingBindingElement; if (mtom == null) return false; if (this.maxReadPoolSize != mtom.MaxReadPoolSize) return false; if (this.maxWritePoolSize != mtom.MaxWritePoolSize) return false; // compare XmlDictionaryReaderQuotas if (this.readerQuotas.MaxStringContentLength != mtom.ReaderQuotas.MaxStringContentLength) return false; if (this.readerQuotas.MaxArrayLength != mtom.ReaderQuotas.MaxArrayLength) return false; if (this.readerQuotas.MaxBytesPerRead != mtom.ReaderQuotas.MaxBytesPerRead) return false; if (this.readerQuotas.MaxDepth != mtom.ReaderQuotas.MaxDepth) return false; if (this.readerQuotas.MaxNameTableCharCount != mtom.ReaderQuotas.MaxNameTableCharCount) return false; if (this.maxBufferSize != mtom.MaxBufferSize) return false; if (this.WriteEncoding.EncodingName != mtom.WriteEncoding.EncodingName) return false; if (!this.MessageVersion.IsMatch(mtom.MessageVersion)) return false; return true; } } } // 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
- LogicalMethodInfo.cs
- XmlSchemaSearchPattern.cs
- Help.cs
- ListViewGroupConverter.cs
- ValidationErrorEventArgs.cs
- XmlAttributeOverrides.cs
- OutputScopeManager.cs
- ElementMarkupObject.cs
- MonthChangedEventArgs.cs
- LayoutEditorPart.cs
- TextEndOfParagraph.cs
- Int32Storage.cs
- MarkupProperty.cs
- _ProxyChain.cs
- DataBindingCollection.cs
- LongMinMaxAggregationOperator.cs
- OdbcTransaction.cs
- DataObjectSettingDataEventArgs.cs
- BindingListCollectionView.cs
- TextServicesDisplayAttributePropertyRanges.cs
- WebServiceEnumData.cs
- Vector3DKeyFrameCollection.cs
- StructuredTypeInfo.cs
- VSWCFServiceContractGenerator.cs
- BinaryReader.cs
- keycontainerpermission.cs
- DashStyle.cs
- XPathChildIterator.cs
- UniqueIdentifierService.cs
- ObjectParameterCollection.cs
- Security.cs
- PartialTrustVisibleAssembly.cs
- TreeViewItemAutomationPeer.cs
- documentsequencetextcontainer.cs
- AdvancedBindingPropertyDescriptor.cs
- PageStatePersister.cs
- FontInfo.cs
- HttpGetServerProtocol.cs
- TextSerializer.cs
- TextPenaltyModule.cs
- XmlnsDictionary.cs
- XPathCompileException.cs
- ToolStripSettings.cs
- MatrixAnimationUsingKeyFrames.cs
- SslStream.cs
- TypeExtensions.cs
- CatalogPartDesigner.cs
- DataContractJsonSerializer.cs
- EntityCommand.cs
- regiisutil.cs
- InitializerFacet.cs
- PassportAuthenticationEventArgs.cs
- BaseUriHelper.cs
- EncoderExceptionFallback.cs
- ClientRoleProvider.cs
- CategoryNameCollection.cs
- ObjectDataSourceChooseTypePanel.cs
- OracleString.cs
- TemplateControlParser.cs
- XmlCharType.cs
- OracleConnectionString.cs
- KerberosSecurityTokenProvider.cs
- SchemaDeclBase.cs
- StorageBasedPackageProperties.cs
- RequestCacheValidator.cs
- safex509handles.cs
- ToolStripCodeDomSerializer.cs
- CookielessHelper.cs
- EventManager.cs
- HandleTable.cs
- StackSpiller.Bindings.cs
- TiffBitmapDecoder.cs
- AssemblyGen.cs
- GridViewRowCollection.cs
- RolePrincipal.cs
- X509ThumbprintKeyIdentifierClause.cs
- RangeBaseAutomationPeer.cs
- HostedImpersonationContext.cs
- SplitterDesigner.cs
- ConfigXmlElement.cs
- DesignerAutoFormat.cs
- XmlAutoDetectWriter.cs
- ElementInit.cs
- FilterEventArgs.cs
- BitmapFrameDecode.cs
- InputMethodStateChangeEventArgs.cs
- EventLogEntryCollection.cs
- GlobalAllocSafeHandle.cs
- Models.cs
- WebPartVerbsEventArgs.cs
- ProcessHostConfigUtils.cs
- Lock.cs
- SetterBaseCollection.cs
- ImageBrush.cs
- SerializationObjectManager.cs
- TextElement.cs
- DataServiceBuildProvider.cs
- StrokeCollectionDefaultValueFactory.cs
- ApplicationException.cs
- QueueProcessor.cs