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 static bool TryGet(Message message, out NetworkInterfaceMessageProperty property) { if (message == null) { throw FxTrace.Exception.ArgumentNull("message"); } return TryGet(message.Properties, out property); }
public static bool TryGet(Message message, out NetworkInterfaceMessageProperty property) { if (message == null) { throw FxTrace.Exception.ArgumentNull("message"); } return(TryGet(message.Properties, out property)); }
public static bool TryGet(MessageProperties properties, out NetworkInterfaceMessageProperty property) { if (properties == null) { throw FxTrace.Exception.ArgumentNull("properties"); } object value = null; if (properties.TryGetValue(PropertyName, out value)) { property = value as NetworkInterfaceMessageProperty; } else { property = null; } return property != null; }
public static bool TryGet(MessageProperties properties, out NetworkInterfaceMessageProperty property) { if (properties == null) { throw FxTrace.Exception.ArgumentNull("properties"); } object value = null; if (properties.TryGetValue(PropertyName, out value)) { property = value as NetworkInterfaceMessageProperty; } else { property = null; } return(property != null); }
public static Message DecodeMessage(DuplicateMessageDetector duplicateDetector, MessageEncoder encoder, BufferManager bufferManager, ArraySegment <byte> data, IPEndPoint remoteEndPoint, int interfaceIndex, bool ignoreSerializationException, out string messageHash) { Fx.Assert(data != null, "data can't be null"); Fx.Assert(remoteEndPoint != null, "remoteEndPoint can't be null"); Fx.Assert(encoder != null, "encoder can't be null"); Fx.Assert(bufferManager != null, "bufferManager can't be null"); Message message = null; messageHash = null; if (duplicateDetector == null || !duplicateDetector.IsDuplicate(data, out messageHash)) { try { message = encoder.ReadMessage(data, bufferManager); } catch (XmlException error) { // Don't throw serialization exceptions when the channel supports Multicast if (!ignoreSerializationException) { throw; } FxTrace.Exception.AsWarning(error); } if (message != null) { message.Properties.Add(RemoteEndpointMessageProperty.Name, new RemoteEndpointMessageProperty(remoteEndPoint.Address.ToString(), remoteEndPoint.Port)); NetworkInterfaceMessageProperty networkInterfaceMessageProperty = new NetworkInterfaceMessageProperty(interfaceIndex); networkInterfaceMessageProperty.AddTo(message); } } return(message); }
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; }
NetworkInterfaceMessageProperty(NetworkInterfaceMessageProperty other) { this.InterfaceIndex = other.InterfaceIndex; }
public static Message DecodeMessage(DuplicateMessageDetector duplicateDetector, MessageEncoder encoder, BufferManager bufferManager, ArraySegment<byte> data, IPEndPoint remoteEndPoint, int interfaceIndex, bool ignoreSerializationException, out string messageHash) { Fx.Assert(data != null, "data can't be null"); Fx.Assert(remoteEndPoint != null, "remoteEndPoint can't be null"); Fx.Assert(encoder != null, "encoder can't be null"); Fx.Assert(bufferManager != null, "bufferManager can't be null"); Message message = null; messageHash = null; if (duplicateDetector == null || !duplicateDetector.IsDuplicate(data, out messageHash)) { try { message = encoder.ReadMessage(data, bufferManager); } catch (XmlException error) { // Don't throw serialization exceptions when the channel supports Multicast if (!ignoreSerializationException) { throw; } FxTrace.Exception.AsWarning(error); } if (message != null) { message.Properties.Add(RemoteEndpointMessageProperty.Name, new RemoteEndpointMessageProperty(remoteEndPoint.Address.ToString(), remoteEndPoint.Port)); NetworkInterfaceMessageProperty networkInterfaceMessageProperty = new NetworkInterfaceMessageProperty(interfaceIndex); networkInterfaceMessageProperty.AddTo(message); } } return message; }