| | | 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.ComponentModel; |
| | | 5 | | using System.Xml; |
| | | 6 | | using CoreWCF.Channels; |
| | | 7 | | |
| | | 8 | | namespace CoreWCF |
| | | 9 | | { |
| | | 10 | | public class NetTcpBinding : Binding |
| | | 11 | | { |
| | | 12 | | // private BindingElements |
| | | 13 | | private TcpTransportBindingElement _transport; |
| | | 14 | | private BinaryMessageEncodingBindingElement _encoding; |
| | 116 | 15 | | private NetTcpSecurity _security = new NetTcpSecurity(); |
| | | 16 | | |
| | 348 | 17 | | public NetTcpBinding() { Initialize(); } |
| | | 18 | | public NetTcpBinding(SecurityMode securityMode) |
| | 75 | 19 | | : this() |
| | | 20 | | { |
| | 75 | 21 | | _security.Mode = securityMode; |
| | 75 | 22 | | } |
| | | 23 | | |
| | | 24 | | public TransferMode TransferMode |
| | | 25 | | { |
| | 2 | 26 | | get { return _transport.TransferMode; } |
| | 98 | 27 | | set { _transport.TransferMode = value; } |
| | | 28 | | } |
| | | 29 | | |
| | | 30 | | public HostNameComparisonMode HostNameComparisonMode |
| | | 31 | | { |
| | 0 | 32 | | get { return _transport.HostNameComparisonMode; } |
| | 18 | 33 | | set { _transport.HostNameComparisonMode = value; } |
| | | 34 | | } |
| | | 35 | | |
| | | 36 | | [DefaultValue(TransportDefaults.MaxBufferPoolSize)] |
| | | 37 | | public long MaxBufferPoolSize |
| | | 38 | | { |
| | 0 | 39 | | get { return _transport.MaxBufferPoolSize; } |
| | | 40 | | set |
| | | 41 | | { |
| | 9 | 42 | | _transport.MaxBufferPoolSize = value; |
| | 9 | 43 | | } |
| | | 44 | | } |
| | | 45 | | |
| | | 46 | | public int MaxBufferSize |
| | | 47 | | { |
| | 2 | 48 | | get { return _transport.MaxBufferSize; } |
| | 18 | 49 | | set { _transport.MaxBufferSize = value; } |
| | | 50 | | } |
| | | 51 | | |
| | | 52 | | public int MaxConnections |
| | | 53 | | { |
| | 0 | 54 | | get { return _transport.MaxPendingConnections; } |
| | | 55 | | set |
| | | 56 | | { |
| | 9 | 57 | | _transport.MaxPendingConnections = value; |
| | 9 | 58 | | } |
| | | 59 | | } |
| | | 60 | | |
| | | 61 | | public int ListenBacklog |
| | | 62 | | { |
| | 0 | 63 | | get { return _transport.ListenBacklog; } |
| | 0 | 64 | | set { _transport.ListenBacklog = value; } |
| | | 65 | | } |
| | | 66 | | |
| | | 67 | | public long MaxReceivedMessageSize |
| | | 68 | | { |
| | 5 | 69 | | get { return _transport.MaxReceivedMessageSize; } |
| | 20 | 70 | | set { _transport.MaxReceivedMessageSize = value; } |
| | | 71 | | } |
| | | 72 | | |
| | | 73 | | public XmlDictionaryReaderQuotas ReaderQuotas |
| | | 74 | | { |
| | 1 | 75 | | get { return _encoding.ReaderQuotas; } |
| | | 76 | | set |
| | | 77 | | { |
| | 9 | 78 | | if (value == null) |
| | | 79 | | { |
| | 0 | 80 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(value)); |
| | | 81 | | } |
| | | 82 | | |
| | 9 | 83 | | value.CopyTo(_encoding.ReaderQuotas); |
| | 9 | 84 | | } |
| | | 85 | | } |
| | | 86 | | |
| | | 87 | | //TODO: Work out if we want IBindingRuntimePreferences. Probably not as we're aiming for 100% async here |
| | | 88 | | //bool IBindingRuntimePreferences.ReceiveSynchronously |
| | | 89 | | //{ |
| | | 90 | | // get { return false; } |
| | | 91 | | //} |
| | | 92 | | |
| | 153 | 93 | | public override string Scheme { get { return _transport.Scheme; } } |
| | | 94 | | |
| | | 95 | | public EnvelopeVersion EnvelopeVersion |
| | | 96 | | { |
| | 0 | 97 | | get { return EnvelopeVersion.Soap12; } |
| | | 98 | | } |
| | | 99 | | |
| | | 100 | | internal SecurityBindingElement CreateMessageSecurity() |
| | | 101 | | { |
| | 1122 | 102 | | if (Security.Mode == SecurityMode.Message || Security.Mode == SecurityMode.TransportWithMessageCredential) |
| | | 103 | | { |
| | 37 | 104 | | return Security.CreateMessageSecurity(false);//ReliableSession.Enabled); |
| | | 105 | | } |
| | | 106 | | else |
| | | 107 | | { |
| | 1085 | 108 | | return null; |
| | | 109 | | } |
| | | 110 | | } |
| | | 111 | | |
| | | 112 | | public NetTcpSecurity Security |
| | | 113 | | { |
| | 2320 | 114 | | get { return _security; } |
| | | 115 | | set |
| | | 116 | | { |
| | 1 | 117 | | _security = value ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(value)); |
| | 1 | 118 | | } |
| | | 119 | | } |
| | | 120 | | |
| | | 121 | | private void Initialize() |
| | | 122 | | { |
| | 116 | 123 | | _transport = new TcpTransportBindingElement(); |
| | 116 | 124 | | _encoding = new BinaryMessageEncodingBindingElement(); |
| | 116 | 125 | | } |
| | | 126 | | |
| | | 127 | | public override BindingElementCollection CreateBindingElements() |
| | | 128 | | { |
| | | 129 | | // return collection of BindingElements |
| | 1122 | 130 | | BindingElementCollection bindingElements = new BindingElementCollection |
| | 1122 | 131 | | { |
| | 1122 | 132 | | // order of BindingElements is important |
| | 1122 | 133 | | // add encoding |
| | 1122 | 134 | | _encoding |
| | 1122 | 135 | | }; |
| | 1122 | 136 | | SecurityBindingElement wsSecurity = CreateMessageSecurity(); |
| | 1122 | 137 | | if (wsSecurity != null) |
| | | 138 | | { |
| | 37 | 139 | | bindingElements.Add(wsSecurity); |
| | | 140 | | } |
| | | 141 | | // add transport security |
| | 1122 | 142 | | BindingElement transportSecurity = CreateTransportSecurity(); |
| | 1122 | 143 | | if (transportSecurity != null) |
| | | 144 | | { |
| | 209 | 145 | | bindingElements.Add(transportSecurity); |
| | | 146 | | } |
| | | 147 | | // TODO: Add ExtendedProtectionPolicy |
| | 1122 | 148 | | _transport.ExtendedProtectionPolicy = _security.Transport.ExtendedProtectionPolicy; |
| | | 149 | | // add transport (tcp) |
| | 1122 | 150 | | bindingElements.Add(_transport); |
| | | 151 | | |
| | 1122 | 152 | | return bindingElements.Clone(); |
| | | 153 | | } |
| | | 154 | | |
| | | 155 | | private BindingElement CreateTransportSecurity() |
| | | 156 | | { |
| | 1122 | 157 | | return _security.CreateTransportSecurity(); |
| | | 158 | | } |
| | | 159 | | } |
| | | 160 | | } |