| | | 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.ComponentModel; |
| | | 6 | | using System.Net; |
| | | 7 | | using System.Text; |
| | | 8 | | using System.Xml; |
| | | 9 | | using CoreWCF.Channels; |
| | | 10 | | using CoreWCF.Runtime; |
| | | 11 | | |
| | | 12 | | namespace CoreWCF |
| | | 13 | | { |
| | | 14 | | public abstract class HttpBindingBase : Binding |
| | | 15 | | { |
| | | 16 | | private readonly HttpTransportBindingElement _httpTransport; |
| | | 17 | | private readonly HttpsTransportBindingElement _httpsTransport; |
| | | 18 | | |
| | 342 | 19 | | internal HttpBindingBase() |
| | | 20 | | { |
| | 342 | 21 | | _httpTransport = new HttpTransportBindingElement(); |
| | 342 | 22 | | _httpsTransport = new HttpsTransportBindingElement(); |
| | 342 | 23 | | TextMessageEncodingBindingElement = new TextMessageEncodingBindingElement |
| | 342 | 24 | | { |
| | 342 | 25 | | MessageVersion = MessageVersion.Soap11 |
| | 342 | 26 | | }; |
| | 342 | 27 | | MtomMessageEncodingBindingElement = new MtomMessageEncodingBindingElement |
| | 342 | 28 | | { |
| | 342 | 29 | | MessageVersion = MessageVersion.Soap11 |
| | 342 | 30 | | }; |
| | | 31 | | |
| | 342 | 32 | | _httpsTransport.WebSocketSettings = _httpTransport.WebSocketSettings; |
| | 342 | 33 | | } |
| | | 34 | | |
| | | 35 | | // [System.ComponentModel.DefaultValueAttribute(false)] |
| | | 36 | | // public bool AllowCookies { get { return default(bool); } set { } } |
| | | 37 | | |
| | | 38 | | // [System.ComponentModel.DefaultValueAttribute((long)524288)] |
| | | 39 | | // public long MaxBufferPoolSize { get { return default(long); } set { } } |
| | | 40 | | |
| | | 41 | | [DefaultValue(TransportDefaults.MaxReceivedMessageSize)] |
| | | 42 | | public long MaxReceivedMessageSize |
| | | 43 | | { |
| | | 44 | | get |
| | | 45 | | { |
| | 6 | 46 | | return _httpTransport.MaxReceivedMessageSize; |
| | | 47 | | } |
| | | 48 | | set |
| | | 49 | | { |
| | 15 | 50 | | _httpTransport.MaxReceivedMessageSize = value; |
| | 15 | 51 | | _httpsTransport.MaxReceivedMessageSize = value; |
| | 15 | 52 | | } |
| | | 53 | | } |
| | | 54 | | |
| | | 55 | | public int MaxBufferSize |
| | | 56 | | { |
| | 6 | 57 | | get { return _httpTransport.MaxBufferSize; } |
| | | 58 | | set |
| | | 59 | | { |
| | 14 | 60 | | _httpTransport.MaxBufferSize = value; |
| | 14 | 61 | | _httpsTransport.MaxBufferSize = value; |
| | 14 | 62 | | MtomMessageEncodingBindingElement.MaxBufferSize = value; |
| | 14 | 63 | | } |
| | | 64 | | } |
| | | 65 | | |
| | | 66 | | public XmlDictionaryReaderQuotas ReaderQuotas |
| | | 67 | | { |
| | | 68 | | get |
| | | 69 | | { |
| | 2 | 70 | | return TextMessageEncodingBindingElement.ReaderQuotas; |
| | | 71 | | } |
| | | 72 | | |
| | | 73 | | set |
| | | 74 | | { |
| | 6 | 75 | | if (value == null) |
| | | 76 | | { |
| | 0 | 77 | | throw Fx.Exception.ArgumentNull(nameof(value)); |
| | | 78 | | } |
| | | 79 | | |
| | 6 | 80 | | value.CopyTo(TextMessageEncodingBindingElement.ReaderQuotas); |
| | 6 | 81 | | value.CopyTo(MtomMessageEncodingBindingElement.ReaderQuotas); |
| | | 82 | | |
| | 6 | 83 | | SetReaderQuotas(value); |
| | 6 | 84 | | } |
| | | 85 | | } |
| | | 86 | | |
| | 1189 | 87 | | public override string Scheme { get { return GetTransport().Scheme; } } |
| | | 88 | | |
| | | 89 | | public Encoding TextEncoding |
| | | 90 | | { |
| | | 91 | | get |
| | | 92 | | { |
| | 0 | 93 | | return TextMessageEncodingBindingElement.WriteEncoding; |
| | | 94 | | } |
| | | 95 | | |
| | | 96 | | set |
| | | 97 | | { |
| | 6 | 98 | | TextMessageEncodingBindingElement.WriteEncoding = value; |
| | 6 | 99 | | MtomMessageEncodingBindingElement.WriteEncoding = value; |
| | 6 | 100 | | } |
| | | 101 | | } |
| | | 102 | | |
| | | 103 | | [DefaultValue(HttpTransportDefaults.TransferMode)] |
| | | 104 | | public TransferMode TransferMode |
| | | 105 | | { |
| | | 106 | | get |
| | | 107 | | { |
| | 6 | 108 | | return _httpTransport.TransferMode; |
| | | 109 | | } |
| | | 110 | | |
| | | 111 | | set |
| | | 112 | | { |
| | 17 | 113 | | _httpTransport.TransferMode = value; |
| | 17 | 114 | | _httpsTransport.TransferMode = value; |
| | 17 | 115 | | } |
| | | 116 | | } |
| | | 117 | | |
| | 7102 | 118 | | internal TextMessageEncodingBindingElement TextMessageEncodingBindingElement { get; } |
| | | 119 | | |
| | 3679 | 120 | | internal MtomMessageEncodingBindingElement MtomMessageEncodingBindingElement { get; } |
| | | 121 | | |
| | | 122 | | internal abstract BasicHttpSecurity BasicHttpSecurity |
| | | 123 | | { |
| | | 124 | | get; |
| | | 125 | | } |
| | | 126 | | |
| | | 127 | | internal WebSocketTransportSettings InternalWebSocketSettings |
| | | 128 | | { |
| | | 129 | | get |
| | | 130 | | { |
| | 62 | 131 | | return _httpTransport.WebSocketSettings; |
| | | 132 | | } |
| | | 133 | | } |
| | | 134 | | |
| | | 135 | | internal TransportBindingElement GetTransport() |
| | | 136 | | { |
| | | 137 | | Fx.Assert(BasicHttpSecurity != null, "this.BasicHttpSecurity should not return null from a derived class."); |
| | | 138 | | |
| | 4979 | 139 | | BasicHttpSecurity basicHttpSecurity = BasicHttpSecurity; |
| | 4979 | 140 | | switch (basicHttpSecurity.Mode) |
| | | 141 | | { |
| | | 142 | | case BasicHttpSecurityMode.Message: |
| | 0 | 143 | | throw new PlatformNotSupportedException(nameof(BasicHttpSecurityMode.Message)); |
| | | 144 | | case BasicHttpSecurityMode.Transport: |
| | | 145 | | case BasicHttpSecurityMode.TransportWithMessageCredential: |
| | 533 | 146 | | basicHttpSecurity.EnableTransportSecurity(_httpsTransport); |
| | 533 | 147 | | basicHttpSecurity.ApplyAuthorizationPolicySupport(_httpsTransport); |
| | 533 | 148 | | return _httpsTransport; |
| | | 149 | | case BasicHttpSecurityMode.TransportCredentialOnly: |
| | 974 | 150 | | basicHttpSecurity.EnableTransportAuthentication(_httpTransport); |
| | 974 | 151 | | basicHttpSecurity.ApplyAuthorizationPolicySupport(_httpTransport); |
| | 974 | 152 | | return _httpTransport; |
| | | 153 | | default: |
| | | 154 | | // ensure that there is no transport security |
| | 3472 | 155 | | basicHttpSecurity.DisableTransportAuthentication(_httpTransport); |
| | 3472 | 156 | | basicHttpSecurity.ApplyAuthorizationPolicySupport(_httpTransport); |
| | 3472 | 157 | | return _httpTransport; |
| | | 158 | | } |
| | | 159 | | } |
| | | 160 | | |
| | | 161 | | internal virtual void SetReaderQuotas(XmlDictionaryReaderQuotas readerQuotas) |
| | | 162 | | { |
| | 4 | 163 | | } |
| | | 164 | | |
| | | 165 | | internal virtual void CheckSettings() |
| | | 166 | | { |
| | | 167 | | //BasicHttpSecurity security = this.BasicHttpSecurity; |
| | | 168 | | //if (security == null) |
| | | 169 | | //{ |
| | | 170 | | // return; |
| | | 171 | | //} |
| | | 172 | | |
| | | 173 | | //BasicHttpSecurityMode mode = security.Mode; |
| | | 174 | | //if (mode == BasicHttpSecurityMode.None) |
| | | 175 | | //{ |
| | | 176 | | // return; |
| | | 177 | | //} |
| | | 178 | | //else if (mode == BasicHttpSecurityMode.Message || mode == BasicHttpSecurityMode.TransportWithMessageCreden |
| | | 179 | | //{ |
| | | 180 | | // throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(SR.Format(SR.Unsup |
| | | 181 | | //} |
| | | 182 | | |
| | | 183 | | //// Transport.ClientCredentialType = InheritedFromHost are not supported. |
| | | 184 | | //Fx.Assert( |
| | | 185 | | // (mode == BasicHttpSecurityMode.Transport) || (mode == BasicHttpSecurityMode.TransportCredentialOnly), |
| | | 186 | | // "Unexpected BasicHttpSecurityMode value: " + mode); |
| | | 187 | | //HttpTransportSecurity transport = security.Transport; |
| | | 188 | | //if (transport != null && transport.ClientCredentialType == HttpClientCredentialType.InheritedFromHost) |
| | | 189 | | //{ |
| | | 190 | | // throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(SR.Format(SR.Unsup |
| | | 191 | | //} |
| | 3790 | 192 | | } |
| | | 193 | | } |
| | | 194 | | } |