//We will use an inner binding element to store information required for the inner encoder //By default, use the default text encoder as the inner encoder public GZipMessageEncodingBindingElement() : this(new TextMessageEncodingBindingElement()) { var textMessageEncodingBindingElement = InnerMessageEncodingBindingElement as TextMessageEncodingBindingElement; ReaderQuotaHelper.SetReaderQuotas(textMessageEncodingBindingElement.ReaderQuotas); }
//Called by the WCF to apply the configuration settings (the property above) to the binding element public override void ApplyConfiguration(BindingElement bindingElement) { GZipMessageEncodingBindingElement binding = (GZipMessageEncodingBindingElement)bindingElement; PropertyInformationCollection propertyInfo = this.ElementInformation.Properties; if (propertyInfo["innerMessageEncoding"].ValueOrigin != PropertyValueOrigin.Default) { switch (this.InnerMessageEncoding) { case "textMessageEncoding": var innerMessageEncodingBindingElement = new TextMessageEncodingBindingElement(); ReaderQuotaHelper.SetReaderQuotas(innerMessageEncodingBindingElement.ReaderQuotas); binding.InnerMessageEncodingBindingElement = innerMessageEncodingBindingElement; break; case "binaryMessageEncoding": var binaryMessageEncodingBindingElement = new BinaryMessageEncodingBindingElement(); ReaderQuotaHelper.SetReaderQuotas(binaryMessageEncodingBindingElement.ReaderQuotas); binding.InnerMessageEncodingBindingElement = binaryMessageEncodingBindingElement; break; } } }