internal UdpChannelFactory(UdpTransportBindingElement transportBindingElement, BindingContext context) : base(context.Binding) { Fx.Assert(transportBindingElement != null, "transportBindingElement can't be null"); Fx.Assert(context != null, "binding context can't be null"); Fx.Assert(typeof(TChannel) == typeof(IOutputChannel) || typeof(TChannel) == typeof(IDuplexChannel), "this channel factory only supports IOutputChannel and IDuplexChannel"); this.udpTransportBindingElement = transportBindingElement; // We should only throw this exception if the user specified realistic MaxReceivedMessageSize less than or equal to max message size over UDP. // If the user specified something bigger like Long.MaxValue, we shouldn't stop them. if (this.udpTransportBindingElement.MaxReceivedMessageSize <= UdpConstants.MaxMessageSizeOverIPv4 && this.udpTransportBindingElement.SocketReceiveBufferSize < this.udpTransportBindingElement.MaxReceivedMessageSize) { throw FxTrace.Exception.ArgumentOutOfRange("SocketReceiveBufferSize", this.udpTransportBindingElement.SocketReceiveBufferSize, SR.Property1LessThanOrEqualToProperty2("MaxReceivedMessageSize", this.udpTransportBindingElement.MaxReceivedMessageSize, "SocketReceiveBufferSize", this.udpTransportBindingElement.SocketReceiveBufferSize)); } this.messageEncoderFactory = UdpUtility.GetEncoder(context); bool retransmissionEnabled = this.udpTransportBindingElement.RetransmissionSettings.Enabled; //duplicated detection doesn't apply to IOutputChannel, so don't throw if we are only sending bool duplicateDetectionEnabled = this.udpTransportBindingElement.DuplicateMessageHistoryLength > 0 ? typeof(TChannel) != typeof(IOutputChannel) : false; UdpUtility.ValidateDuplicateDetectionAndRetransmittionSupport(this.messageEncoderFactory, retransmissionEnabled, duplicateDetectionEnabled); int maxBufferSize = (int)Math.Min(transportBindingElement.MaxReceivedMessageSize, UdpConstants.MaxMessageSizeOverIPv4); this.BufferManager = BufferManager.CreateBufferManager(transportBindingElement.MaxBufferPoolSize, maxBufferSize); }
internal UdpTransportBindingElement(UdpTransportBindingElement other) : base(other) { this.duplicateMessageHistoryLength = other.duplicateMessageHistoryLength; this.maxPendingMessagesTotalSize = other.maxPendingMessagesTotalSize; this.retransmissionSettings = other.retransmissionSettings.Clone(); this.socketReceiveBufferSize = other.socketReceiveBufferSize; this.timeToLive = other.timeToLive; this.MulticastInterfaceId = other.MulticastInterfaceId; }
public void ImportPolicy(MetadataImporter importer, PolicyConversionContext context) { XmlQualifiedName wsdlBindingQName; string transportUri = WsdlImporter.SoapInPolicyWorkaroundHelper.FindAdHocPolicy(context, this.udpTransportUriKey, out wsdlBindingQName); if (transportUri != null && transportUri.Equals(UdpConstants.WsdlSoapUdpTransportUri, StringComparison.Ordinal) && !context.BindingElements.Contains(typeof(TransportBindingElement))) { UdpTransportBindingElement transport = new UdpTransportBindingElement(); ((ITransportPolicyImport)transport).ImportPolicy(importer, context); StateHelper.RegisterTransportBindingElement(importer, wsdlBindingQName); context.BindingElements.Add(transport); } }
internal UdpChannelListener(UdpTransportBindingElement udpTransportBindingElement, BindingContext context) : base(context.Binding) { Fx.Assert(udpTransportBindingElement != null, "udpTransportBindingElement can't be null"); Fx.Assert(context != null, "BindingContext parameter can't be null"); this.udpTransportBindingElement = udpTransportBindingElement; this.cleanedUp = 0; this.duplicateDetector = null; if (udpTransportBindingElement.DuplicateMessageHistoryLength > 0) { this.duplicateDetector = new DuplicateMessageDetector(udpTransportBindingElement.DuplicateMessageHistoryLength); } this.onChannelClosed = new EventHandler(OnChannelClosed); // We should only throw this exception if the user specified realistic MaxReceivedMessageSize less than or equal to max message size over UDP. // If the user specified something bigger like Long.MaxValue, we shouldn't stop them. if (this.udpTransportBindingElement.MaxReceivedMessageSize <= UdpConstants.MaxMessageSizeOverIPv4 && this.udpTransportBindingElement.SocketReceiveBufferSize < this.udpTransportBindingElement.MaxReceivedMessageSize) { throw FxTrace.Exception.ArgumentOutOfRange("SocketReceiveBufferSize", this.udpTransportBindingElement.SocketReceiveBufferSize, SR.Property1LessThanOrEqualToProperty2("MaxReceivedMessageSize", this.udpTransportBindingElement.MaxReceivedMessageSize, "SocketReceiveBufferSize", this.udpTransportBindingElement.SocketReceiveBufferSize)); } int maxBufferSize = (int)Math.Min(udpTransportBindingElement.MaxReceivedMessageSize, UdpConstants.MaxMessageSizeOverIPv4); this.bufferManager = BufferManager.CreateBufferManager(udpTransportBindingElement.MaxBufferPoolSize, maxBufferSize); this.messageEncoderFactory = UdpUtility.GetEncoder(context); UdpUtility.ValidateDuplicateDetectionAndRetransmittionSupport(this.messageEncoderFactory, this.udpTransportBindingElement.RetransmissionSettings.Enabled, this.udpTransportBindingElement.DuplicateMessageHistoryLength > 0); InitUri(context); //Note: because we are binding the sockets in InitSockets, we can start receiving data immediately. //If there is a delay between the Building of the listener and the call to Open, stale data could build up //inside the Winsock buffer. We have decided that making sure the port is updated correctly in the listen uri //(e.g. in the ListenUriMode.Unique case) before leaving the build step is more important than the //potential for stale data. InitSockets(context.ListenUriMode == ListenUriMode.Unique); Fx.Assert(!this.listenUri.IsDefaultPort, "Listen Uri's port should never be the default port: " + this.listenUri); }
internal static void ExportRetransmissionEnabledAssertion(UdpTransportBindingElement bindingElement, PolicyAssertionCollection assertions) { if (bindingElement == null) { throw FxTrace.Exception.ArgumentNull("bindingElement"); } if (assertions == null) { throw FxTrace.Exception.ArgumentNull("assertions"); } if (bindingElement.RetransmissionSettings.Enabled) { XmlElement assertion = Document.CreateElement(UdpConstants.WsdlSoapUdpTransportPrefix, UdpConstants.RetransmissionEnabled, UdpConstants.WsdlSoapUdpTransportNamespace); assertions.Add(assertion); } }
internal override bool IsMatch(BindingElement b) { if (!base.IsMatch(b)) { return(false); } UdpTransportBindingElement udpTransport = b as UdpTransportBindingElement; if (udpTransport == null) { return(false); } if (this.DuplicateMessageHistoryLength != udpTransport.DuplicateMessageHistoryLength) { return(false); } if (this.MaxPendingMessagesTotalSize != udpTransport.MaxPendingMessagesTotalSize) { return(false); } if (!String.Equals(this.MulticastInterfaceId, udpTransport.MulticastInterfaceId, StringComparison.OrdinalIgnoreCase)) { return(false); } if (!this.RetransmissionSettings.IsMatch(udpTransport.RetransmissionSettings)) { return(false); } if (this.TimeToLive != udpTransport.TimeToLive) { return(false); } return(true); }
public UdpReplyChannelListener(UdpTransportBindingElement udpTransportBindingElement, BindingContext context) : base(udpTransportBindingElement, context) { }