| | | 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.Xml; |
| | | 7 | | using CoreWCF.Channels; |
| | | 8 | | |
| | | 9 | | namespace CoreWCF |
| | | 10 | | { |
| | | 11 | | public abstract class WSHttpBindingBase : Binding //, IBindingRuntimePreferences |
| | | 12 | | { |
| | | 13 | | private TextMessageEncodingBindingElement _textEncoding; |
| | | 14 | | private MtomMessageEncodingBindingElement _mtomEncoding; |
| | | 15 | | |
| | | 16 | | protected WSHttpBindingBase() |
| | 41 | 17 | | : base() |
| | | 18 | | { |
| | 41 | 19 | | Initialize(); |
| | 41 | 20 | | } |
| | | 21 | | |
| | 35 | 22 | | protected WSHttpBindingBase(bool reliableSessionEnabled) : this() |
| | | 23 | | { |
| | 35 | 24 | | if (reliableSessionEnabled) |
| | | 25 | | { |
| | 0 | 26 | | throw new PlatformNotSupportedException(); |
| | | 27 | | } |
| | 35 | 28 | | } |
| | | 29 | | |
| | | 30 | | [DefaultValue(false)] |
| | | 31 | | public bool TransactionFlow |
| | | 32 | | { |
| | 0 | 33 | | get { return false; } |
| | | 34 | | set |
| | | 35 | | { |
| | 0 | 36 | | if (value) |
| | | 37 | | { |
| | 0 | 38 | | throw new PlatformNotSupportedException(); |
| | | 39 | | } |
| | 0 | 40 | | } |
| | | 41 | | } |
| | | 42 | | |
| | | 43 | | // [DefaultValue(TransportDefaults.MaxBufferPoolSize)] |
| | | 44 | | public long MaxBufferPoolSize |
| | | 45 | | { |
| | 2 | 46 | | get { return HttpTransport.MaxBufferPoolSize; } |
| | | 47 | | set |
| | | 48 | | { |
| | 2 | 49 | | HttpTransport.MaxBufferPoolSize = value; |
| | 2 | 50 | | HttpsTransport.MaxBufferPoolSize = value; |
| | 2 | 51 | | } |
| | | 52 | | } |
| | | 53 | | |
| | | 54 | | [DefaultValue(TransportDefaults.MaxReceivedMessageSize)] |
| | | 55 | | public long MaxReceivedMessageSize |
| | | 56 | | { |
| | 2 | 57 | | get { return HttpTransport.MaxReceivedMessageSize; } |
| | | 58 | | set |
| | | 59 | | { |
| | 2 | 60 | | if (value > int.MaxValue) |
| | | 61 | | { |
| | 0 | 62 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError( |
| | 0 | 63 | | new ArgumentOutOfRangeException(nameof(MaxReceivedMessageSize), |
| | 0 | 64 | | SR.MaxReceivedMessageSizeMustBeInIntegerRange)); |
| | | 65 | | } |
| | 2 | 66 | | HttpTransport.MaxReceivedMessageSize = value; |
| | 2 | 67 | | HttpsTransport.MaxReceivedMessageSize = value; |
| | 2 | 68 | | _mtomEncoding.MaxBufferSize = (int)value; |
| | 2 | 69 | | } |
| | | 70 | | } |
| | | 71 | | |
| | 403 | 72 | | public WSMessageEncoding MessageEncoding { get; set; } |
| | | 73 | | |
| | | 74 | | public XmlDictionaryReaderQuotas ReaderQuotas |
| | | 75 | | { |
| | 1 | 76 | | get { return _textEncoding.ReaderQuotas; } |
| | | 77 | | set |
| | | 78 | | { |
| | 2 | 79 | | if (value == null) |
| | | 80 | | { |
| | 0 | 81 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(value)); |
| | | 82 | | } |
| | | 83 | | |
| | 2 | 84 | | value.CopyTo(_textEncoding.ReaderQuotas); |
| | 2 | 85 | | value.CopyTo(_mtomEncoding.ReaderQuotas); |
| | 2 | 86 | | } |
| | | 87 | | } |
| | | 88 | | |
| | 148 | 89 | | public override string Scheme { get { return GetTransport().Scheme; } } |
| | | 90 | | |
| | | 91 | | public EnvelopeVersion EnvelopeVersion |
| | | 92 | | { |
| | 0 | 93 | | get { return EnvelopeVersion.Soap12; } |
| | | 94 | | } |
| | | 95 | | |
| | | 96 | | //public Text.Encoding TextEncoding |
| | | 97 | | //{ |
| | | 98 | | // get { return _textEncoding.WriteEncoding; } |
| | | 99 | | // set |
| | | 100 | | // { |
| | | 101 | | // _textEncoding.WriteEncoding = value; |
| | | 102 | | // _mtomEncoding.WriteEncoding = value; |
| | | 103 | | // } |
| | | 104 | | //} |
| | | 105 | | |
| | 369 | 106 | | internal HttpTransportBindingElement HttpTransport { get; private set; } |
| | | 107 | | |
| | 839 | 108 | | internal HttpsTransportBindingElement HttpsTransport { get; private set; } |
| | | 109 | | |
| | | 110 | | private void Initialize() |
| | | 111 | | { |
| | 41 | 112 | | HttpTransport = new HttpTransportBindingElement(); |
| | 41 | 113 | | HttpsTransport = new HttpsTransportBindingElement(); |
| | 41 | 114 | | _textEncoding = new TextMessageEncodingBindingElement |
| | 41 | 115 | | { |
| | 41 | 116 | | MessageVersion = MessageVersion.Soap12WSAddressing10 |
| | 41 | 117 | | }; |
| | 41 | 118 | | _mtomEncoding = new MtomMessageEncodingBindingElement |
| | 41 | 119 | | { |
| | 41 | 120 | | MessageVersion = MessageVersion.Soap12WSAddressing10 |
| | 41 | 121 | | }; |
| | 41 | 122 | | } |
| | | 123 | | |
| | | 124 | | public override BindingElementCollection CreateBindingElements() |
| | | 125 | | { // return collection of BindingElements |
| | 343 | 126 | | BindingElementCollection bindingElements = new BindingElementCollection(); |
| | | 127 | | // order of BindingElements is important |
| | | 128 | | // context |
| | | 129 | | |
| | | 130 | | // add security (*optional) |
| | 343 | 131 | | SecurityBindingElement wsSecurity = CreateMessageSecurity(); |
| | 343 | 132 | | if (wsSecurity != null) |
| | | 133 | | { |
| | 137 | 134 | | bindingElements.Add(wsSecurity); |
| | | 135 | | } |
| | | 136 | | |
| | | 137 | | // add encoding (text or mtom) |
| | 343 | 138 | | WSMessageEncodingHelper.SyncUpEncodingBindingElementProperties(_textEncoding, _mtomEncoding); |
| | 343 | 139 | | if (MessageEncoding == WSMessageEncoding.Text) |
| | | 140 | | { |
| | 291 | 141 | | bindingElements.Add(_textEncoding); |
| | | 142 | | } |
| | 52 | 143 | | else if (MessageEncoding == WSMessageEncoding.Mtom) |
| | | 144 | | { |
| | 52 | 145 | | bindingElements.Add(_mtomEncoding); |
| | | 146 | | } |
| | | 147 | | |
| | | 148 | | // add transport (http or https) |
| | 343 | 149 | | bindingElements.Add(GetTransport()); |
| | | 150 | | |
| | 343 | 151 | | return bindingElements.Clone(); |
| | | 152 | | } |
| | | 153 | | |
| | | 154 | | protected abstract TransportBindingElement GetTransport(); |
| | | 155 | | protected abstract SecurityBindingElement CreateMessageSecurity(); |
| | | 156 | | } |
| | | 157 | | } |