< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Channels.ConnectionOrientedTransportBindingElement
Assembly: CoreWCF.NetFramingBase
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.NetFramingBase/src/CoreWCF/Channels/ConnectionOrientedTransportBindingElement.cs
Line coverage
63%
Covered lines: 92
Uncovered lines: 53
Coverable lines: 145
Total lines: 421
Line coverage: 63.4%
Branch coverage
35%
Covered branches: 23
Total branches: 64
Branch coverage: 35.9%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.NetFramingBase/src/CoreWCF/Channels/ConnectionOrientedTransportBindingElement.cs

#LineLine coverage
 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
 4using System;
 5using System.Collections.Generic;
 6using System.ComponentModel;
 7using System.Xml;
 8using CoreWCF.Description;
 9using CoreWCF.Runtime;
 10
 11namespace CoreWCF.Channels
 12{
 13    public abstract class ConnectionOrientedTransportBindingElement : TransportBindingElement, IWsdlExportExtension, IPo
 14    {
 15        private int _connectionBufferSize;
 16        private readonly bool _exposeConnectionProperty;
 17        private HostNameComparisonMode _hostNameComparisonMode;
 18        private TimeSpan _channelInitializationTimeout;
 19        private int _maxBufferSize;
 20        private bool _maxBufferSizeInitialized;
 21        private int _maxPendingConnections;
 22        private TimeSpan _maxOutputDelay;
 23        private int _maxPendingAccepts;
 24        private TransferMode _transferMode;
 25
 12726        protected ConnectionOrientedTransportBindingElement() : base()
 27        {
 12728            _connectionBufferSize = ConnectionOrientedTransportDefaults.ConnectionBufferSize;
 12729            _hostNameComparisonMode = ConnectionOrientedTransportDefaults.HostNameComparisonMode;
 12730            _channelInitializationTimeout = ConnectionOrientedTransportDefaults.ChannelInitializationTimeout;
 12731            _maxBufferSize = TransportDefaults.MaxBufferSize;
 12732            _maxPendingConnections = ConnectionOrientedTransportDefaults.GetMaxPendingConnections();
 12733            _maxOutputDelay = ConnectionOrientedTransportDefaults.MaxOutputDelay;
 12734            _maxPendingAccepts = ConnectionOrientedTransportDefaults.GetMaxPendingAccepts();
 12735            _transferMode = ConnectionOrientedTransportDefaults.TransferMode;
 12736        }
 37
 190538        protected ConnectionOrientedTransportBindingElement(ConnectionOrientedTransportBindingElement elementToBeCloned)
 39        {
 190540            _connectionBufferSize = elementToBeCloned._connectionBufferSize;
 190541            _exposeConnectionProperty = elementToBeCloned._exposeConnectionProperty;
 190542            _hostNameComparisonMode = elementToBeCloned._hostNameComparisonMode;
 190543            InheritBaseAddressSettings = elementToBeCloned.InheritBaseAddressSettings;
 190544            _channelInitializationTimeout = elementToBeCloned.ChannelInitializationTimeout;
 190545            _maxBufferSize = elementToBeCloned._maxBufferSize;
 190546            _maxBufferSizeInitialized = elementToBeCloned._maxBufferSizeInitialized;
 190547            _maxPendingConnections = elementToBeCloned._maxPendingConnections;
 190548            _maxOutputDelay = elementToBeCloned._maxOutputDelay;
 190549            _maxPendingAccepts = elementToBeCloned._maxPendingAccepts;
 190550            _transferMode = elementToBeCloned._transferMode;
 190551            IsMaxPendingAcceptsSet = elementToBeCloned.IsMaxPendingAcceptsSet;
 190552        }
 53
 54        [DefaultValue(ConnectionOrientedTransportDefaults.ConnectionBufferSize)]
 55        public int ConnectionBufferSize
 56        {
 57            get
 58            {
 11059                return _connectionBufferSize;
 60            }
 61            set
 62            {
 263                if (value < 0)
 64                {
 065                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val
 066                        SRCommon.ValueMustBeNonNegative));
 67                }
 68
 269                _connectionBufferSize = value;
 270            }
 71        }
 72
 73        [DefaultValue(ConnectionOrientedTransportDefaults.HostNameComparisonMode)]
 74        public HostNameComparisonMode HostNameComparisonMode
 75        {
 76            get
 77            {
 11078                return _hostNameComparisonMode;
 79            }
 80
 81            set
 82            {
 1183                HostNameComparisonModeHelper.Validate(value);
 1184                _hostNameComparisonMode = value;
 1185            }
 86        }
 87
 88        [DefaultValue(TransportDefaults.MaxBufferSize)]
 89        public int MaxBufferSize
 90        {
 91            get
 92            {
 11293                if (_maxBufferSizeInitialized || TransferMode != TransferMode.Buffered)
 94                {
 3995                    return _maxBufferSize;
 96                }
 97
 7398                long maxReceivedMessageSize = MaxReceivedMessageSize;
 7399                if (maxReceivedMessageSize > int.MaxValue)
 100                {
 0101                    return int.MaxValue;
 102                }
 103                else
 104                {
 73105                    return (int)maxReceivedMessageSize;
 106                }
 107            }
 108            set
 109            {
 10110                if (value <= 0)
 111                {
 0112                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val
 0113                        SRCommon.ValueMustBePositive));
 114                }
 115
 10116                _maxBufferSizeInitialized = true;
 10117                _maxBufferSize = value;
 10118            }
 119        }
 120
 121        public int MaxPendingConnections
 122        {
 123            get
 124            {
 1125                return _maxPendingConnections;
 126            }
 127            set
 128            {
 10129                if (value <= 0)
 130                {
 0131                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val
 0132                        SRCommon.ValueMustBePositive));
 133                }
 134
 10135                _maxPendingConnections = value;
 10136            }
 137        }
 138
 0139        internal bool IsMaxPendingConnectionsSet { get; private set; }
 140
 141        // used by MEX to ensure that we don't conflict on base-address scoped settings
 3810142        internal bool InheritBaseAddressSettings { get; set; }
 143
 144        public TimeSpan ChannelInitializationTimeout
 145        {
 146            get
 147            {
 1907148                return _channelInitializationTimeout;
 149            }
 150
 151            set
 152            {
 2153                if (value <= TimeSpan.Zero)
 154                {
 0155                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val
 0156                        SRCommon.TimeSpanMustBeGreaterThanTimeSpanZero));
 157                }
 158
 2159                if (TimeoutHelper.IsTooLarge(value))
 160                {
 0161                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val
 0162                        SRCommon.SFxTimeoutOutOfRangeTooBig));
 163                }
 164
 2165                _channelInitializationTimeout = value;
 2166            }
 167        }
 168
 169        public TimeSpan MaxOutputDelay
 170        {
 171            get
 172            {
 2173                return _maxOutputDelay;
 174            }
 175
 176            set
 177            {
 2178                if (value < TimeSpan.Zero)
 179                {
 0180                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val
 0181                        SRCommon.SFxTimeoutOutOfRange0));
 182                }
 183
 2184                if (TimeoutHelper.IsTooLarge(value))
 185                {
 0186                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val
 0187                        SRCommon.SFxTimeoutOutOfRangeTooBig));
 188                }
 189
 2190                _maxOutputDelay = value;
 2191            }
 192        }
 193
 194        public int MaxPendingAccepts
 195        {
 196            get
 197            {
 1198                return _maxPendingAccepts;
 199            }
 200
 201            set
 202            {
 1203                if (value <= 0)
 204                {
 0205                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val
 0206                        SRCommon.ValueMustBePositive));
 207                }
 208
 1209                _maxPendingAccepts = value;
 1210                IsMaxPendingAcceptsSet = true;
 1211            }
 212        }
 213
 214        public override bool CanBuildServiceDispatcher<TChannel>(BindingContext context)
 215        {
 117216            if (context == null)
 217            {
 0218                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(context));
 219            }
 220
 117221            return true;
 222        }
 223
 3811224        internal bool IsMaxPendingAcceptsSet { get; private set; }
 225
 226        [DefaultValue(ConnectionOrientedTransportDefaults.TransferMode)]
 227        public TransferMode TransferMode
 228        {
 229            get
 230            {
 221231                return _transferMode;
 232            }
 233            set
 234            {
 51235                TransferModeHelper.Validate(value);
 51236                _transferMode = value;
 51237            }
 238        }
 239
 240        void IPolicyExportExtension.ExportPolicy(MetadataExporter exporter, PolicyConversionContext context)
 241        {
 1242            if (exporter == null)
 243            {
 0244                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(exporter));
 245            }
 246
 1247            if (context == null)
 248            {
 0249                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(context));
 250            }
 251
 1252            ICollection<XmlElement> policyAssertions = context.GetBindingAssertions();
 1253            if (TransferModeHelper.IsRequestStreamed(TransferMode)
 1254                || TransferModeHelper.IsResponseStreamed(TransferMode))
 255            {
 0256                policyAssertions.Add(new XmlDocument().CreateElement(TransportPolicyConstants.DotNetFramingPrefix,
 0257                    TransportPolicyConstants.StreamedName, TransportPolicyConstants.DotNetFramingNamespace));
 258            }
 259
 260            bool createdNew;
 1261            MessageEncodingBindingElement encodingBindingElement = FindMessageEncodingBindingElement(context.BindingElem
 1262            if (createdNew && encodingBindingElement is IPolicyExportExtension)
 263            {
 0264                encodingBindingElement = new BinaryMessageEncodingBindingElement();
 0265                ((IPolicyExportExtension)encodingBindingElement).ExportPolicy(exporter, context);
 266            }
 267
 1268            WsdlExporter.AddWSAddressingAssertion(exporter, context, encodingBindingElement.MessageVersion.Addressing);
 1269        }
 270
 0271        void IWsdlExportExtension.ExportContract(WsdlExporter exporter, WsdlContractConversionContext context) { }
 272
 273        protected abstract string WsdlTransportUri { get; }
 274
 275        void IWsdlExportExtension.ExportEndpoint(WsdlExporter exporter, WsdlEndpointConversionContext endpointContext)
 276        {
 277            bool createdNew;
 1278            MessageEncodingBindingElement encodingBindingElement = FindMessageEncodingBindingElement(endpointContext, ou
 1279            ExportWsdlEndpoint(exporter, endpointContext, WsdlTransportUri, encodingBindingElement.MessageVersion.Addres
 1280        }
 281
 282        private MessageEncodingBindingElement FindMessageEncodingBindingElement(BindingElementCollection bindingElements
 283        {
 2284            createdNew = false;
 2285            MessageEncodingBindingElement encodingBindingElement = bindingElements.Find<MessageEncodingBindingElement>()
 2286            if (encodingBindingElement == null)
 287            {
 0288                createdNew = true;
 0289                encodingBindingElement = new BinaryMessageEncodingBindingElement();
 290            }
 2291            return encodingBindingElement;
 292        }
 293
 294        private MessageEncodingBindingElement FindMessageEncodingBindingElement(WsdlEndpointConversionContext endpointCo
 295        {
 1296            BindingElementCollection bindingElements = endpointContext.Endpoint.Binding.CreateBindingElements();
 1297            return FindMessageEncodingBindingElement(bindingElements, out createdNew);
 298        }
 299
 300        public override T GetProperty<T>(BindingContext context)
 301        {
 330302            if (context == null)
 303            {
 0304                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(context));
 305            }
 330306            if (typeof(T) == typeof(TransferMode))
 307            {
 0308                return (T)(object)TransferMode;
 309            }
 310            else
 311            {
 330312                return base.GetProperty<T>(context);
 313            }
 314        }
 315
 316        protected override bool IsMatch(BindingElement b)
 317        {
 0318            if (!base.IsMatch(b))
 319            {
 0320                return false;
 321            }
 322
 0323            if (!(b is ConnectionOrientedTransportBindingElement connection))
 324            {
 0325                return false;
 326            }
 327
 0328            if (_connectionBufferSize != connection._connectionBufferSize)
 329            {
 0330                return false;
 331            }
 332
 0333            if (_hostNameComparisonMode != connection._hostNameComparisonMode)
 334            {
 0335                return false;
 336            }
 337
 0338            if (InheritBaseAddressSettings != connection.InheritBaseAddressSettings)
 339            {
 0340                return false;
 341            }
 342
 0343            if (_channelInitializationTimeout != connection._channelInitializationTimeout)
 344            {
 0345                return false;
 346            }
 0347            if (_maxBufferSize != connection._maxBufferSize)
 348            {
 0349                return false;
 350            }
 351
 0352            if (_maxPendingConnections != connection._maxPendingConnections)
 353            {
 0354                return false;
 355            }
 356
 0357            if (_maxOutputDelay != connection._maxOutputDelay)
 358            {
 0359                return false;
 360            }
 361
 0362            if (_maxPendingAccepts != connection._maxPendingAccepts)
 363            {
 0364                return false;
 365            }
 366
 0367            if (_transferMode != connection._transferMode)
 368            {
 0369                return false;
 370            }
 371
 0372            return true;
 373        }
 374
 375        // Originally lived on ConnectionOrientedTransportChannelListener in WCF
 19376        internal protected virtual bool SupportsUpgrade(StreamUpgradeBindingElement streamUpgradeBindingElement) => true
 377
 378        internal static void ExportWsdlEndpoint(WsdlExporter exporter, WsdlEndpointConversionContext endpointContext,
 379            string wsdlTransportUri, AddressingVersion addressingVersion)
 380        {
 1381            ExportWsdlEndpoint(exporter, endpointContext, wsdlTransportUri, endpointContext.Endpoint.Address, addressing
 1382        }
 383    }
 384
 385    // Originally lived in TransportBindingElementImporter.cs
 386    internal static class TransportPolicyConstants
 387    {
 388        public const string BasicHttpAuthenticationName = "BasicAuthentication";
 389        public const string CompositeDuplex = "CompositeDuplex";
 390        public const string CompositeDuplexNamespace = "http://schemas.microsoft.com/net/2006/06/duplex";
 391        public const string CompositeDuplexPrefix = "cdp";
 392        public const string DigestHttpAuthenticationName = "DigestAuthentication";
 393        public const string DotNetFramingNamespace = Framing.FramingEncodingString.NamespaceUri + "/policy";
 394        public const string DotNetFramingPrefix = "msf";
 395        public const string HttpTransportNamespace = "http://schemas.microsoft.com/ws/06/2004/policy/http";
 396        public const string HttpTransportPrefix = "http";
 397        public const string HttpTransportUri = "http://schemas.xmlsoap.org/soap/http";
 398        public const string MsmqBestEffort = "MsmqBestEffort";
 399        public const string MsmqSession = "MsmqSession";
 400        public const string MsmqTransportNamespace = "http://schemas.microsoft.com/ws/06/2004/mspolicy/msmq";
 401        public const string MsmqTransportPrefix = "msmq";
 402        public const string MsmqTransportUri = "http://schemas.microsoft.com/soap/msmq";
 403        public const string MsmqVolatile = "MsmqVolatile";
 404        public const string MsmqAuthenticated = "Authenticated";
 405        public const string MsmqWindowsDomain = "WindowsDomain";
 406        public const string NamedPipeTransportUri = "http://schemas.microsoft.com/soap/named-pipe";
 407        public const string NegotiateHttpAuthenticationName = "NegotiateAuthentication";
 408        public const string NtlmHttpAuthenticationName = "NtlmAuthentication";
 409        public const string PeerTransportUri = "http://schemas.microsoft.com/soap/peer";
 410        public const string ProtectionLevelName = "ProtectionLevel";
 411        public const string RequireClientCertificateName = "RequireClientCertificate";
 412        public const string SslTransportSecurityName = "SslTransportSecurity";
 413        public const string StreamedName = "Streamed";
 414        public const string TcpTransportUri = "http://schemas.microsoft.com/soap/tcp";
 415        public const string WebSocketPolicyPrefix = "mswsp";
 416        public const string WebSocketPolicyNamespace = "http://schemas.microsoft.com/soap/websocket/policy";
 417        public const string WebSocketTransportUri = "http://schemas.microsoft.com/soap/websocket";
 418        public const string WebSocketEnabled = "WebSocketEnabled";
 419        public const string WindowsTransportSecurityName = "WindowsTransportSecurity";
 420    }
 421}

Methods/Properties

.ctor()
.ctor(CoreWCF.Channels.ConnectionOrientedTransportBindingElement)
ConnectionBufferSize()
ConnectionBufferSize(System.Int32)
HostNameComparisonMode()
HostNameComparisonMode(CoreWCF.HostNameComparisonMode)
MaxBufferSize()
MaxBufferSize(System.Int32)
MaxPendingConnections()
MaxPendingConnections(System.Int32)
IsMaxPendingConnectionsSet()
InheritBaseAddressSettings()
ChannelInitializationTimeout()
ChannelInitializationTimeout(System.TimeSpan)
MaxOutputDelay()
MaxOutputDelay(System.TimeSpan)
MaxPendingAccepts()
MaxPendingAccepts(System.Int32)
CanBuildServiceDispatcher(CoreWCF.Channels.BindingContext)
IsMaxPendingAcceptsSet()
TransferMode()
TransferMode(CoreWCF.TransferMode)
CoreWCF.Description.IPolicyExportExtension.ExportPolicy(CoreWCF.Description.MetadataExporter,CoreWCF.Description.PolicyConversionContext)
CoreWCF.Description.IWsdlExportExtension.ExportContract(CoreWCF.Description.WsdlExporter,CoreWCF.Description.WsdlContractConversionContext)
CoreWCF.Description.IWsdlExportExtension.ExportEndpoint(CoreWCF.Description.WsdlExporter,CoreWCF.Description.WsdlEndpointConversionContext)
FindMessageEncodingBindingElement(CoreWCF.Channels.BindingElementCollection,System.Boolean&)
FindMessageEncodingBindingElement(CoreWCF.Description.WsdlEndpointConversionContext,System.Boolean&)
GetProperty(CoreWCF.Channels.BindingContext)
IsMatch(CoreWCF.Channels.BindingElement)
SupportsUpgrade(CoreWCF.Channels.StreamUpgradeBindingElement)
ExportWsdlEndpoint(CoreWCF.Description.WsdlExporter,CoreWCF.Description.WsdlEndpointConversionContext,System.String,CoreWCF.Channels.AddressingVersion)