private UdpSocket GetSendSocketUsingInterfaceIndex(MessageProperties properties, out Exception exceptionToBeThrown) { NetworkInterfaceMessageProperty property; UdpSocket socket = null; exceptionToBeThrown = null; if (!NetworkInterfaceMessageProperty.TryGet(properties, out property)) { if (this.SendSockets.Length > 1) { // this property is required on all messages sent from the channel listener. // the client channel does not use this method to get the send SendSockets or the // remote endpoint, so it is safe to throw... exceptionToBeThrown = new InvalidOperationException(SR.NetworkInterfaceMessagePropertyMissing(typeof(NetworkInterfaceMessageProperty))); } else { // there is only one socket, so just send it on that one. socket = this.SendSockets[0]; } } else { socket = this.GetSendSocket(property.InterfaceIndex, out exceptionToBeThrown); } return(socket); }
public UdpRequestContext(UdpOutputChannel outputChannel, Message requestMessage) : base(requestMessage, outputChannel.InternalCloseTimeout, outputChannel.InternalSendTimeout) { Fx.Assert(outputChannel != null, "replyChannel can't be null"); this.outputChannel = outputChannel; if (!NetworkInterfaceMessageProperty.TryGet(requestMessage, out this.networkInterfaceMessageProperty)) { Fx.Assert("requestMessage must always contain NetworkInterfaceMessageProperty"); } RemoteEndpointMessageProperty remoteEndpointMessageProperty; if (!requestMessage.Properties.TryGetValue(RemoteEndpointMessageProperty.Name, out remoteEndpointMessageProperty)) { Fx.Assert("requestMessage must always contain RemoteEndpointMessageProperty"); } UriBuilder uriBuilder = new UriBuilder(UdpConstants.Scheme, remoteEndpointMessageProperty.Address, remoteEndpointMessageProperty.Port); this.via = uriBuilder.Uri; }