internal static MessageQueue Lookup(Uri uri, IPAddress address, int port)
        {
            if (TD.RoutingTableLookupStartIsEnabled())
            {
                TD.RoutingTableLookupStart();
            }

            Uri wildCardUri = uri;
            UriPrefixTable <MessageQueueAndPath> table = namedPipeMessageQueues;

            if (address != null)
            {
                // Including port number to support TCP proxy (see MB56472). We only use it for wildcard matching below.
                // NOTE: we don't need to call TcpChannelListener.FixIpv6Hostname to fix the host name because it's ignored anyway.
                UriBuilder uriBuilder = new UriBuilder(uri.Scheme, uri.Host, port, uri.PathAndQuery);
                wildCardUri = uriBuilder.Uri;
                table       = tcpMessageQueues;
            }

            MessageQueueAndPath found = null;
            bool success = table.TryLookupUri(wildCardUri, HostNameComparisonMode.StrongWildcard, out found);

            if (success && address != null)
            {
                success = ValidateAddress(address, ref found);
            }
            if (!success)
            {
                success = table.TryLookupUri(uri, HostNameComparisonMode.Exact, out found);
                if (success && address != null)
                {
                    success = ValidateAddress(address, ref found);
                }
            }
            if (!success)
            {
                success = table.TryLookupUri(wildCardUri, HostNameComparisonMode.WeakWildcard, out found);
                if (success && address != null)
                {
                    success = ValidateAddress(address, ref found);
                }
            }

            if (DiagnosticUtility.ShouldTraceInformation)
            {
                ListenerTraceUtility.TraceEvent(TraceEventType.Information, ListenerTraceCode.RoutingTableLookup, SR.GetString(SR.TraceCodeRoutingTableLookup), new StringTraceRecord("Uri", uri.ToString()), null, null);
            }

            Debug.Print("RoutingTable.Lookup(" + uri + ") matched: " + (found == null ? "<NoMatch!>" : found.Uri.ToString()));
            if (TD.RoutingTableLookupStopIsEnabled())
            {
                TD.RoutingTableLookupStop();
            }
            return(found == null ? null : found.MessageQueue);
        }