| | | 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.Collections.ObjectModel; |
| | | 6 | | using System.Xml; |
| | | 7 | | using CoreWCF.Description; |
| | | 8 | | using CoreWCF.Security; |
| | | 9 | | using WsdlNS = System.Web.Services.Description; |
| | | 10 | | |
| | | 11 | | namespace CoreWCF.Channels |
| | | 12 | | { |
| | | 13 | | public abstract class TransportBindingElement : BindingElement |
| | | 14 | | { |
| | | 15 | | private bool _manualAddressing; |
| | | 16 | | private long _maxBufferPoolSize; |
| | | 17 | | private long _maxReceivedMessageSize; |
| | | 18 | | |
| | 1652 | 19 | | protected TransportBindingElement() |
| | | 20 | | { |
| | 1652 | 21 | | _manualAddressing = TransportDefaults.ManualAddressing; |
| | 1652 | 22 | | _maxBufferPoolSize = TransportDefaults.MaxBufferPoolSize; |
| | 1652 | 23 | | _maxReceivedMessageSize = TransportDefaults.MaxReceivedMessageSize; |
| | 1652 | 24 | | } |
| | | 25 | | |
| | 10259 | 26 | | protected TransportBindingElement(TransportBindingElement elementToBeCloned) |
| | | 27 | | { |
| | 10259 | 28 | | _manualAddressing = elementToBeCloned._manualAddressing; |
| | 10259 | 29 | | _maxBufferPoolSize = elementToBeCloned._maxBufferPoolSize; |
| | 10259 | 30 | | _maxReceivedMessageSize = elementToBeCloned._maxReceivedMessageSize; |
| | 10259 | 31 | | } |
| | | 32 | | |
| | | 33 | | [System.ComponentModel.DefaultValueAttribute(false)] |
| | | 34 | | public virtual bool ManualAddressing |
| | | 35 | | { |
| | | 36 | | get |
| | | 37 | | { |
| | 1178 | 38 | | return _manualAddressing; |
| | | 39 | | } |
| | | 40 | | |
| | | 41 | | set |
| | | 42 | | { |
| | 84 | 43 | | _manualAddressing = value; |
| | 84 | 44 | | } |
| | | 45 | | } |
| | | 46 | | |
| | | 47 | | public virtual long MaxBufferPoolSize |
| | | 48 | | { |
| | | 49 | | get |
| | | 50 | | { |
| | 533 | 51 | | return _maxBufferPoolSize; |
| | | 52 | | } |
| | | 53 | | set |
| | | 54 | | { |
| | 23 | 55 | | if (value < 0) |
| | | 56 | | { |
| | 0 | 57 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val |
| | 0 | 58 | | SRCommon.ValueMustBeNonNegative)); |
| | | 59 | | } |
| | 23 | 60 | | _maxBufferPoolSize = value; |
| | 23 | 61 | | } |
| | | 62 | | } |
| | | 63 | | |
| | | 64 | | [System.ComponentModel.DefaultValueAttribute((long)65536)] |
| | | 65 | | public virtual long MaxReceivedMessageSize |
| | | 66 | | { |
| | | 67 | | get |
| | | 68 | | { |
| | 3441 | 69 | | return _maxReceivedMessageSize; |
| | | 70 | | } |
| | | 71 | | set |
| | | 72 | | { |
| | 69 | 73 | | if (value <= 0) |
| | | 74 | | { |
| | 0 | 75 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val |
| | 0 | 76 | | SRCommon.ValueMustBePositive)); |
| | | 77 | | } |
| | 69 | 78 | | _maxReceivedMessageSize = value; |
| | 69 | 79 | | } |
| | | 80 | | } |
| | | 81 | | |
| | | 82 | | public abstract string Scheme { get; } |
| | | 83 | | |
| | | 84 | | public override T GetProperty<T>(BindingContext context) |
| | | 85 | | { |
| | 1154 | 86 | | if (context == null) |
| | | 87 | | { |
| | 0 | 88 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(context)); |
| | | 89 | | } |
| | | 90 | | |
| | 1154 | 91 | | if (typeof(T) == typeof(ChannelProtectionRequirements)) |
| | | 92 | | { |
| | 9 | 93 | | ChannelProtectionRequirements myRequirements = GetProtectionRequirements(context); |
| | 9 | 94 | | myRequirements.Add(context.GetInnerProperty<ChannelProtectionRequirements>() ?? new ChannelProtectionReq |
| | 9 | 95 | | return (T)(object)myRequirements; |
| | | 96 | | } |
| | | 97 | | |
| | | 98 | | // to cover all our bases, let's iterate through the BindingParameters to make sure |
| | | 99 | | // we haven't missed a query (since we're the Transport and we're at the bottom) |
| | 1145 | 100 | | Collection<BindingElement> bindingElements = new Collection<BindingElement>(); |
| | 3480 | 101 | | foreach (object param in context.BindingParameters) |
| | | 102 | | { |
| | 595 | 103 | | if (param is BindingElement element) |
| | | 104 | | { |
| | 375 | 105 | | bindingElements.Add(element); |
| | | 106 | | } |
| | | 107 | | } |
| | | 108 | | |
| | 3038 | 109 | | for (int i = 0; i < bindingElements.Count; i++) |
| | | 110 | | { |
| | 375 | 111 | | T result = bindingElements[i].GetIndividualProperty<T>(); |
| | 375 | 112 | | if (result != default(T)) |
| | | 113 | | { |
| | 1 | 114 | | return result; |
| | | 115 | | } |
| | | 116 | | } |
| | | 117 | | |
| | 1144 | 118 | | if (typeof(T) == typeof(MessageVersion)) |
| | | 119 | | { |
| | 227 | 120 | | return (T)(object)TransportDefaults.GetDefaultMessageEncoderFactory().MessageVersion; |
| | | 121 | | } |
| | | 122 | | |
| | 917 | 123 | | if (typeof(T) == typeof(XmlDictionaryReaderQuotas)) |
| | | 124 | | { |
| | 6 | 125 | | return (T)(object)new XmlDictionaryReaderQuotas(); |
| | | 126 | | } |
| | | 127 | | |
| | 911 | 128 | | return null; |
| | | 129 | | } |
| | | 130 | | |
| | | 131 | | private ChannelProtectionRequirements GetProtectionRequirements(AddressingVersion addressingVersion) |
| | | 132 | | { |
| | 9 | 133 | | ChannelProtectionRequirements result = new ChannelProtectionRequirements(); |
| | 9 | 134 | | result.IncomingSignatureParts.AddParts(addressingVersion.SignedMessageParts); |
| | 9 | 135 | | result.OutgoingSignatureParts.AddParts(addressingVersion.SignedMessageParts); |
| | 9 | 136 | | return result; |
| | | 137 | | } |
| | | 138 | | |
| | | 139 | | internal ChannelProtectionRequirements GetProtectionRequirements(BindingContext context) |
| | | 140 | | { |
| | 9 | 141 | | AddressingVersion addressingVersion = AddressingVersion.WSAddressing10; |
| | 9 | 142 | | MessageEncodingBindingElement messageEncoderBindingElement = context.Binding.Elements.Find<MessageEncodingBi |
| | 9 | 143 | | if (messageEncoderBindingElement != null) |
| | | 144 | | { |
| | 9 | 145 | | addressingVersion = messageEncoderBindingElement.MessageVersion.Addressing; |
| | | 146 | | } |
| | | 147 | | |
| | 9 | 148 | | return GetProtectionRequirements(addressingVersion); |
| | | 149 | | } |
| | | 150 | | |
| | | 151 | | public static void ExportWsdlEndpoint(WsdlExporter exporter, WsdlEndpointConversionContext endpointContext, |
| | | 152 | | string wsdlTransportUri, EndpointAddress address, AddressingVersion addressingVersion) |
| | | 153 | | { |
| | 32 | 154 | | if (exporter == null) |
| | | 155 | | { |
| | 0 | 156 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(exporter)); |
| | | 157 | | } |
| | | 158 | | |
| | 32 | 159 | | if (endpointContext == null) |
| | | 160 | | { |
| | 0 | 161 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(endpointContext)); |
| | | 162 | | } |
| | | 163 | | |
| | | 164 | | // Set SoapBinding Transport URI |
| | 32 | 165 | | if (wsdlTransportUri != null) |
| | | 166 | | { |
| | 32 | 167 | | WsdlNS.SoapBinding soapBinding = SoapHelper.GetOrCreateSoapBinding(endpointContext, exporter); |
| | | 168 | | |
| | 32 | 169 | | if (soapBinding != null) |
| | | 170 | | { |
| | 32 | 171 | | soapBinding.Transport = wsdlTransportUri; |
| | | 172 | | } |
| | | 173 | | } |
| | | 174 | | |
| | 32 | 175 | | if (endpointContext.WsdlPort != null) |
| | | 176 | | { |
| | 32 | 177 | | WsdlExporter.WSAddressingHelper.AddAddressToWsdlPort(endpointContext.WsdlPort, address, addressingVersio |
| | | 178 | | } |
| | 32 | 179 | | } |
| | | 180 | | |
| | | 181 | | protected override bool IsMatch(BindingElement b) |
| | | 182 | | { |
| | 0 | 183 | | if (b == null) |
| | | 184 | | { |
| | 0 | 185 | | return false; |
| | | 186 | | } |
| | 0 | 187 | | if (!(b is TransportBindingElement transport)) |
| | | 188 | | { |
| | 0 | 189 | | return false; |
| | | 190 | | } |
| | 0 | 191 | | if (_maxBufferPoolSize != transport.MaxBufferPoolSize) |
| | | 192 | | { |
| | 0 | 193 | | return false; |
| | | 194 | | } |
| | 0 | 195 | | if (_maxReceivedMessageSize != transport.MaxReceivedMessageSize) |
| | | 196 | | { |
| | 0 | 197 | | return false; |
| | | 198 | | } |
| | 0 | 199 | | return true; |
| | | 200 | | } |
| | | 201 | | } |
| | | 202 | | } |