1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291
|
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
namespace System.ServiceModel.Channels
{
using System.ServiceModel.Activation;
using System.Collections.Generic;
using System.Net;
using System.Net.Security;
using System.Net.Sockets;
using System.Runtime.Serialization;
using System.Security.Authentication.ExtendedProtection;
using System.Xml;
using System.ComponentModel;
public class TcpTransportBindingElement : ConnectionOrientedTransportBindingElement
{
int listenBacklog;
bool portSharingEnabled;
bool teredoEnabled;
TcpConnectionPoolSettings connectionPoolSettings;
ExtendedProtectionPolicy extendedProtectionPolicy;
bool isListenBacklogSet;
public TcpTransportBindingElement()
: base()
{
this.listenBacklog = TcpTransportDefaults.GetListenBacklog();
this.portSharingEnabled = TcpTransportDefaults.PortSharingEnabled;
this.teredoEnabled = TcpTransportDefaults.TeredoEnabled;
this.connectionPoolSettings = new TcpConnectionPoolSettings();
this.extendedProtectionPolicy = ChannelBindingUtility.DefaultPolicy;
}
protected TcpTransportBindingElement(TcpTransportBindingElement elementToBeCloned)
: base(elementToBeCloned)
{
this.listenBacklog = elementToBeCloned.listenBacklog;
this.isListenBacklogSet = elementToBeCloned.isListenBacklogSet;
this.portSharingEnabled = elementToBeCloned.portSharingEnabled;
this.teredoEnabled = elementToBeCloned.teredoEnabled;
this.connectionPoolSettings = elementToBeCloned.connectionPoolSettings.Clone();
this.extendedProtectionPolicy = elementToBeCloned.ExtendedProtectionPolicy;
}
public TcpConnectionPoolSettings ConnectionPoolSettings
{
get { return this.connectionPoolSettings; }
}
public int ListenBacklog
{
get
{
return this.listenBacklog;
}
set
{
if (value <= 0)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value",
SR.GetString(SR.ValueMustBePositive)));
}
this.listenBacklog = value;
this.isListenBacklogSet = true;
}
}
internal bool IsListenBacklogSet
{
get { return this.isListenBacklogSet; }
}
// server
[DefaultValue(TcpTransportDefaults.PortSharingEnabled)]
public bool PortSharingEnabled
{
get
{
return this.portSharingEnabled;
}
set
{
this.portSharingEnabled = value;
}
}
public override string Scheme
{
get { return "net.tcp"; }
}
// server
[DefaultValue(TcpTransportDefaults.TeredoEnabled)]
public bool TeredoEnabled
{
get
{
return this.teredoEnabled;
}
set
{
this.teredoEnabled = value;
}
}
public ExtendedProtectionPolicy ExtendedProtectionPolicy
{
get
{
return this.extendedProtectionPolicy;
}
set
{
if (value == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("value");
}
if (value.PolicyEnforcement == PolicyEnforcement.Always &&
!System.Security.Authentication.ExtendedProtection.ExtendedProtectionPolicy.OSSupportsExtendedProtection)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
new PlatformNotSupportedException(SR.GetString(SR.ExtendedProtectionNotSupported)));
}
this.extendedProtectionPolicy = value;
}
}
internal override string WsdlTransportUri
{
get
{
return TransportPolicyConstants.TcpTransportUri;
}
}
public override BindingElement Clone()
{
return new TcpTransportBindingElement(this);
}
public override IChannelFactory<TChannel> BuildChannelFactory<TChannel>(BindingContext context)
{
if (context == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context");
}
if (!this.CanBuildChannelFactory<TChannel>(context))
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("TChannel", SR.GetString(SR.ChannelTypeNotSupported, typeof(TChannel)));
}
return (IChannelFactory<TChannel>)(object)new TcpChannelFactory<TChannel>(this, context);
}
public override IChannelListener<TChannel> BuildChannelListener<TChannel>(BindingContext context)
{
if (context == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context");
}
if (!this.CanBuildChannelListener<TChannel>(context))
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("TChannel", SR.GetString(SR.ChannelTypeNotSupported, typeof(TChannel)));
}
TcpChannelListener listener;
if (typeof(TChannel) == typeof(IReplyChannel))
{
listener = new TcpReplyChannelListener(this, context);
}
else if (typeof(TChannel) == typeof(IDuplexSessionChannel))
{
listener = new TcpDuplexChannelListener(this, context);
}
else
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("TChannel", SR.GetString(SR.ChannelTypeNotSupported, typeof(TChannel)));
}
AspNetEnvironment.Current.ApplyHostedContext(listener, context);
return (IChannelListener<TChannel>)(object)listener;
}
public override T GetProperty<T>(BindingContext context)
{
if (context == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context");
}
if (typeof(T) == typeof(IBindingDeliveryCapabilities))
{
return (T)(object)new BindingDeliveryCapabilitiesHelper();
}
else if (typeof(T) == typeof(ExtendedProtectionPolicy))
{
return (T)(object)this.ExtendedProtectionPolicy;
}
else if (typeof(T) == typeof(ITransportCompressionSupport))
{
return (T)(object)new TransportCompressionSupportHelper();
}
else
{
return base.GetProperty<T>(context);
}
}
internal override bool IsMatch(BindingElement b)
{
if (!base.IsMatch(b))
{
return false;
}
TcpTransportBindingElement tcp = b as TcpTransportBindingElement;
if (tcp == null)
{
return false;
}
if (this.listenBacklog != tcp.listenBacklog)
{
return false;
}
if (this.portSharingEnabled != tcp.portSharingEnabled)
{
return false;
}
if (this.teredoEnabled != tcp.teredoEnabled)
{
return false;
}
if (!this.connectionPoolSettings.IsMatch(tcp.connectionPoolSettings))
{
return false;
}
if (!ChannelBindingUtility.AreEqual(this.ExtendedProtectionPolicy, tcp.ExtendedProtectionPolicy))
{
return false;
}
return true;
}
[EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializeExtendedProtectionPolicy()
{
return !ChannelBindingUtility.AreEqual(this.ExtendedProtectionPolicy, ChannelBindingUtility.DefaultPolicy);
}
[EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializeListenBacklog()
{
return this.isListenBacklogSet;
}
class BindingDeliveryCapabilitiesHelper : IBindingDeliveryCapabilities
{
internal BindingDeliveryCapabilitiesHelper()
{
}
bool IBindingDeliveryCapabilities.AssuresOrderedDelivery
{
get { return true; }
}
bool IBindingDeliveryCapabilities.QueuedDelivery
{
get { return false; }
}
}
class TransportCompressionSupportHelper : ITransportCompressionSupport
{
public bool IsCompressionFormatSupported(CompressionFormat compressionFormat)
{
return true;
}
}
}
}
|