| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System; |
| | | 5 | | using System.Text; |
| | | 6 | | using System.Xml; |
| | | 7 | | |
| | | 8 | | namespace CoreWCF.Channels |
| | | 9 | | { |
| | | 10 | | public sealed class WebMessageEncodingBindingElement : MessageEncodingBindingElement//, IWsdlExportExtension |
| | | 11 | | { |
| | | 12 | | private int _maxReadPoolSize; |
| | | 13 | | private int _maxWritePoolSize; |
| | | 14 | | private Encoding _writeEncoding; |
| | | 15 | | |
| | 42 | 16 | | public WebMessageEncodingBindingElement() : this(TextEncoderDefaults.Encoding) |
| | | 17 | | { |
| | 42 | 18 | | } |
| | | 19 | | |
| | 42 | 20 | | public WebMessageEncodingBindingElement(Encoding writeEncoding) |
| | | 21 | | { |
| | 42 | 22 | | if (writeEncoding == null) |
| | | 23 | | { |
| | 0 | 24 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(writeEncoding)); |
| | | 25 | | } |
| | | 26 | | |
| | 42 | 27 | | TextEncoderDefaults.ValidateEncoding(writeEncoding); |
| | 42 | 28 | | _maxReadPoolSize = EncoderDefaults.MaxReadPoolSize; |
| | 42 | 29 | | _maxWritePoolSize = EncoderDefaults.MaxWritePoolSize; |
| | 42 | 30 | | ReaderQuotas = new XmlDictionaryReaderQuotas(); |
| | 42 | 31 | | EncoderDefaults.ReaderQuotas.CopyTo(ReaderQuotas); |
| | 42 | 32 | | _writeEncoding = writeEncoding; |
| | 42 | 33 | | } |
| | | 34 | | |
| | | 35 | | private WebMessageEncodingBindingElement(WebMessageEncodingBindingElement elementToBeCloned) |
| | 849 | 36 | | : base(elementToBeCloned) |
| | | 37 | | { |
| | 849 | 38 | | _maxReadPoolSize = elementToBeCloned._maxReadPoolSize; |
| | 849 | 39 | | _maxWritePoolSize = elementToBeCloned._maxWritePoolSize; |
| | 849 | 40 | | ReaderQuotas = new XmlDictionaryReaderQuotas(); |
| | 849 | 41 | | elementToBeCloned.ReaderQuotas.CopyTo(ReaderQuotas); |
| | 849 | 42 | | _writeEncoding = elementToBeCloned._writeEncoding; |
| | 849 | 43 | | ContentTypeMapper = elementToBeCloned.ContentTypeMapper; |
| | 849 | 44 | | CrossDomainScriptAccessEnabled = elementToBeCloned.CrossDomainScriptAccessEnabled; |
| | 849 | 45 | | } |
| | | 46 | | |
| | 1814 | 47 | | public WebContentTypeMapper ContentTypeMapper { get; set; } |
| | | 48 | | |
| | | 49 | | public int MaxReadPoolSize |
| | | 50 | | { |
| | | 51 | | get |
| | | 52 | | { |
| | 40 | 53 | | return _maxReadPoolSize; |
| | | 54 | | } |
| | | 55 | | set |
| | | 56 | | { |
| | 0 | 57 | | if (value <= 0) |
| | | 58 | | { |
| | 0 | 59 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val |
| | 0 | 60 | | SR.Format(SRCommon.ValueMustBePositive))); |
| | | 61 | | } |
| | | 62 | | |
| | 0 | 63 | | _maxReadPoolSize = value; |
| | 0 | 64 | | } |
| | | 65 | | } |
| | | 66 | | |
| | | 67 | | public int MaxWritePoolSize |
| | | 68 | | { |
| | | 69 | | get |
| | | 70 | | { |
| | 40 | 71 | | return _maxWritePoolSize; |
| | | 72 | | } |
| | | 73 | | set |
| | | 74 | | { |
| | 0 | 75 | | if (value <= 0) |
| | | 76 | | { |
| | 0 | 77 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val |
| | 0 | 78 | | SR.Format(SRCommon.ValueMustBePositive))); |
| | | 79 | | } |
| | | 80 | | |
| | 0 | 81 | | _maxWritePoolSize = value; |
| | 0 | 82 | | } |
| | | 83 | | } |
| | | 84 | | |
| | | 85 | | public override MessageVersion MessageVersion |
| | | 86 | | { |
| | | 87 | | get |
| | | 88 | | { |
| | 220 | 89 | | return MessageVersion.None; |
| | | 90 | | } |
| | | 91 | | set |
| | | 92 | | { |
| | 39 | 93 | | if (value == null) |
| | | 94 | | { |
| | 0 | 95 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(value)); |
| | | 96 | | } |
| | | 97 | | |
| | 39 | 98 | | if (value != MessageVersion.None) |
| | | 99 | | { |
| | 0 | 100 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(nameof(value), SR.Format(SR.JsonOnlySup |
| | | 101 | | } |
| | 39 | 102 | | } |
| | | 103 | | } |
| | | 104 | | |
| | 1784 | 105 | | public XmlDictionaryReaderQuotas ReaderQuotas { get; } |
| | | 106 | | |
| | | 107 | | public Encoding WriteEncoding |
| | | 108 | | { |
| | | 109 | | get |
| | | 110 | | { |
| | 114 | 111 | | return _writeEncoding; |
| | | 112 | | } |
| | | 113 | | set |
| | | 114 | | { |
| | 2 | 115 | | if (value == null) |
| | | 116 | | { |
| | 0 | 117 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(value)); |
| | | 118 | | } |
| | | 119 | | |
| | 2 | 120 | | TextEncoderDefaults.ValidateEncoding(value); |
| | 2 | 121 | | _writeEncoding = value; |
| | 2 | 122 | | } |
| | | 123 | | } |
| | | 124 | | |
| | | 125 | | public bool CrossDomainScriptAccessEnabled |
| | | 126 | | { |
| | 926 | 127 | | get; |
| | 849 | 128 | | set; |
| | | 129 | | } |
| | | 130 | | |
| | | 131 | | public override BindingElement Clone() |
| | | 132 | | { |
| | 849 | 133 | | return new WebMessageEncodingBindingElement(this); |
| | | 134 | | } |
| | | 135 | | |
| | | 136 | | public override MessageEncoderFactory CreateMessageEncoderFactory() |
| | | 137 | | { |
| | 40 | 138 | | return new WebMessageEncoderFactory(WriteEncoding, MaxReadPoolSize, MaxWritePoolSize, ReaderQuotas, ContentT |
| | | 139 | | } |
| | | 140 | | |
| | | 141 | | public override T GetProperty<T>(BindingContext context) |
| | | 142 | | { |
| | 331 | 143 | | if (context == null) |
| | | 144 | | { |
| | 0 | 145 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(context)); |
| | | 146 | | } |
| | 331 | 147 | | if (typeof(T) == typeof(XmlDictionaryReaderQuotas)) |
| | | 148 | | { |
| | 0 | 149 | | return (T)(object)ReaderQuotas; |
| | | 150 | | } |
| | | 151 | | else |
| | | 152 | | { |
| | 331 | 153 | | return base.GetProperty<T>(context); |
| | | 154 | | } |
| | | 155 | | } |
| | | 156 | | |
| | | 157 | | //void IWsdlExportExtension.ExportContract(WsdlExporter exporter, WsdlContractConversionContext context) |
| | | 158 | | //{ |
| | | 159 | | //} |
| | | 160 | | |
| | | 161 | | //void IWsdlExportExtension.ExportEndpoint(WsdlExporter exporter, WsdlEndpointConversionContext context) |
| | | 162 | | //{ |
| | | 163 | | // if (context == null) |
| | | 164 | | // { |
| | | 165 | | // throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context"); |
| | | 166 | | // } |
| | | 167 | | |
| | | 168 | | // SoapHelper.SetSoapVersion(context, exporter, this.MessageVersion.Envelope); |
| | | 169 | | //} |
| | | 170 | | |
| | 0 | 171 | | protected override bool CheckEncodingVersion(EnvelopeVersion version) => MessageVersion.Envelope == version; |
| | | 172 | | |
| | 0 | 173 | | protected override bool IsMatch(BindingElement b) => false; |
| | | 174 | | } |
| | | 175 | | } |