public TcpNetworkChannel(EndpointAddress address) { if (address == null) { throw new ArgumentNullException("address"); } if (!string.Equals(address.Uri.Scheme, uriScheme, StringComparison.InvariantCultureIgnoreCase)) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "The scheme {0} specified in address is not supported.", address.Uri.Scheme), "address"); } remoteAddress = address; viaUri = remoteAddress.Uri; IPAddress remoteIP; // Determine the host name resolution method. switch(Via.HostNameType) { default: throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "Cannot determine the remote host address from {0}.", this.remoteAddress), "address"); case UriHostNameType.IPv4: case UriHostNameType.IPv6: remoteIP = IPAddress.Parse(Via.Host); break; case UriHostNameType.Basic: case UriHostNameType.Dns: { try { IPHostEntry hostEntry = Dns.GetHostEntry(Via.Host); if (hostEntry.AddressList.Length > 0) { remoteIP = hostEntry.AddressList[0]; } else { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "Failed to resolve remote host: {0}.", Via.Host), "address"); } } catch(SocketException socketException) { throw new EndpointNotFoundException(string.Format("Failed to resolve remote host: {0}", Via.Host), socketException); } break; } } remoteEndPoint = new IPEndPoint(remoteIP, Via.Port); tcpSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); remoteIP = null; receivingStopped = new ManualResetEvent(false); }