Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.ServiceModel.Channels;
- using System.ServiceModel.Configuration;
- using System.Configuration;
- using System.ComponentModel;
- using System.Reflection;
- using System.Xml;
- namespace InfoCaster.SocialProxy.lib.TextOrMtom
- {
- public class TextOrMtomEncodingElement : BindingElementExtensionElement
- {
- [ConfigurationProperty("maxArrayLength", DefaultValue = "2147483647")]
- public string MaxArrayLength
- {
- get { return (string)base["maxArrayLength"]; }
- set { base["maxArrayLength"] = value; }
- }
- [ConfigurationProperty("MaxDepth", DefaultValue = "2147483647")]
- public string MaxDepth
- {
- get { return (string)base["MaxDepth"]; }
- set { base["MaxDepth"] = value; }
- }
- [ConfigurationProperty("MaxStringContentLength", DefaultValue = "2147483647")]
- public string MaxStringContentLength
- {
- get { return (string)base["MaxStringContentLength"]; }
- set { base["MaxStringContentLength"] = value; }
- }
- [ConfigurationProperty("MaxBytesPerRead", DefaultValue = "2147483647")]
- public string MaxBytesPerRead
- {
- get { return (string)base["MaxBytesPerRead"]; }
- set { base["MaxBytesPerRead"] = value; }
- }
- /// <summary>
- /// Gets the reader quotas.
- /// </summary>
- /// <value>The reader quotas.</value>
- [ConfigurationProperty("readerQuotas")]
- public XmlDictionaryReaderQuotasElement ReaderQuotas
- {
- get { return (XmlDictionaryReaderQuotasElement)base["readerQuotas"]; }
- set { base["readerQuotas"] = value; }
- }
- /// <summary>
- /// Initializes a new instance of the <see cref="TextOrMtomEncodingElement"/> class.
- /// </summary>
- public TextOrMtomEncodingElement()
- { }
- /// <summary>
- /// When overridden in a derived class, gets the <see cref="T:System.Type"/> object that represents the custom binding element.
- /// </summary>
- /// <value></value>
- /// <returns>A <see cref="T:System.Type"/> object that represents the custom binding type.</returns>
- public override Type BindingElementType
- {
- get { return typeof(TextOrMtomEncodingBindingElement); }
- }
- /// <summary>
- /// Gets or sets the inner message encoding.
- /// </summary>
- /// <value>The inner message encoding.</value>
- [ConfigurationProperty("messageVersion", DefaultValue = "Soap11")]
- public string MessageVersion
- {
- get { return (string)base["messageVersion"]; }
- set { base["messageVersion"] = value; }
- }
- /// <summary>
- /// When overridden in a derived class, returns a custom binding element object.
- /// </summary>
- /// <returns>
- /// A custom <see cref="T:System.ServiceModel.Channels.BindingElement"/> object.
- /// </returns>
- protected override BindingElement CreateBindingElement()
- {
- TextOrMtomEncodingBindingElement bindingElement = new TextOrMtomEncodingBindingElement(this.ReaderQuotas);
- this.ApplyConfiguration(bindingElement);
- return bindingElement;
- }
- public override void ApplyConfiguration(BindingElement bindingElement)
- {
- TextOrMtomEncodingBindingElement binding = (TextOrMtomEncodingBindingElement)bindingElement;
- binding.ReaderQuotas.MaxArrayLength = this.ReaderQuotas.MaxArrayLength;
- binding.ReaderQuotas.MaxBytesPerRead = this.ReaderQuotas.MaxBytesPerRead;
- binding.ReaderQuotas.MaxDepth = this.ReaderQuotas.MaxDepth;
- binding.ReaderQuotas.MaxNameTableCharCount = this.ReaderQuotas.MaxNameTableCharCount;
- binding.ReaderQuotas.MaxStringContentLength = this.ReaderQuotas.MaxStringContentLength;
- // set the soap version here.
- binding.MessageVersion = System.ServiceModel.Channels.MessageVersion.Soap11;
- PropertyInfo pInfo = typeof(System.ServiceModel.Channels.MessageVersion).GetProperty(this.MessageVersion);
- if (pInfo != null)
- binding.MessageVersion = (System.ServiceModel.Channels.MessageVersion)pInfo.GetValue(null, null);
- base.ApplyConfiguration(bindingElement);
- }
- }
- public class TextOrMtomEncodingBindingElement : MessageEncodingBindingElement
- {
- public const string IsIncomingMessageMtomPropertyName = "IncomingMessageIsMtom";
- public const string MtomBoundaryPropertyName = "__MtomBoundary";
- public const string MtomStartInfoPropertyName = "__MtomStartInfo";
- public const string MtomStartUriPropertyName = "__MtomStartUri";
- MessageVersion _messageVersion = MessageVersion.Default;
- XmlDictionaryReaderQuotas _readerQuotas;
- public XmlDictionaryReaderQuotas ReaderQuotas { get { return this._readerQuotas; } }
- public TextOrMtomEncodingBindingElement()
- {
- this._readerQuotas = new XmlDictionaryReaderQuotas();
- }
- public TextOrMtomEncodingBindingElement(TextOrMtomEncodingBindingElement elementToBeCloned)
- : base (elementToBeCloned)
- {
- this._messageVersion = elementToBeCloned.MessageVersion;
- elementToBeCloned.ReaderQuotas.CopyTo(this._readerQuotas);
- }
- public TextOrMtomEncodingBindingElement(XmlDictionaryReaderQuotasElement xmlDictionaryReaderQuotasElement)
- : this()
- {
- this._readerQuotas.MaxArrayLength = xmlDictionaryReaderQuotasElement.MaxArrayLength;
- this._readerQuotas.MaxBytesPerRead = xmlDictionaryReaderQuotasElement.MaxBytesPerRead;
- this._readerQuotas.MaxDepth = xmlDictionaryReaderQuotasElement.MaxDepth;
- this._readerQuotas.MaxNameTableCharCount = xmlDictionaryReaderQuotasElement.MaxNameTableCharCount;
- this._readerQuotas.MaxStringContentLength = xmlDictionaryReaderQuotasElement.MaxStringContentLength;
- }
- public override MessageEncoderFactory CreateMessageEncoderFactory()
- {
- return new TextOrMtomEncoderFactory(this._messageVersion);
- }
- public override MessageVersion MessageVersion
- {
- get { return this._messageVersion; }
- set { this._messageVersion = value; }
- }
- public override BindingElement Clone()
- {
- return this;
- }
- public override T GetProperty<T>(BindingContext context)
- {
- if (typeof(T) == typeof(XmlDictionaryReaderQuotas))
- {
- return (T)(object)this._readerQuotas;
- }
- else
- {
- return base.GetProperty<T>(context);
- }
- }
- public override IChannelFactory<TChannel> BuildChannelFactory<TChannel>(BindingContext context)
- {
- context.BindingParameters.Add(this);
- return context.BuildInnerChannelFactory<TChannel>();
- }
- public override IChannelListener<TChannel> BuildChannelListener<TChannel>(BindingContext context)
- {
- context.BindingParameters.Add(this);
- return context.BuildInnerChannelListener<TChannel>();
- }
- public override bool CanBuildChannelFactory<TChannel>(BindingContext context)
- {
- return context.CanBuildInnerChannelFactory<TChannel>();
- }
- public override bool CanBuildChannelListener<TChannel>(BindingContext context)
- {
- return context.CanBuildInnerChannelListener<TChannel>();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement