Пример #1
0
        public static ServiceAddress ResolveServer(ILogger logger, string serviceName, ServiceAddresses serviceAddrs, string[] requiredContracts)
        {
            var serverList = new List <RoundTripData>();

            foreach (ServiceAddress serviceAddr in serviceAddrs.List)
            {
                Int64 roundTrip; // ticks
                int   maxRoundTrips = 1;
                if (serviceAddrs.List.Count > 1)
                {
                    maxRoundTrips = 3;
                }
                if (QueryService(logger, serviceAddr.Host, serviceAddr.Port, serviceName, requiredContracts, maxRoundTrips, out roundTrip))
                {
                    // add addr to list
                    serverList.Add(new RoundTripData(serviceAddr, roundTrip));
                }
            } // foreach server address
            // find 'nearest' server
            if (serverList.Count > 0)
            {
                ServiceAddress address       = serverList[0].Addr;
                Int64          bestRoundTrip = serverList[0].Ticks;
                foreach (RoundTripData item in serverList)
                {
                    if (item.Ticks < bestRoundTrip)
                    {
                        address       = item.Addr;
                        bestRoundTrip = item.Ticks;
                    }
                }
                return(address);
            }
            throw new EndpointNotFoundException(
                      $"No server in list '{serviceAddrs}' found!");
        }
Пример #2
0
 public RoundTripData(ServiceAddress addr, Int64 ticks)
 {
     Addr = addr; Ticks = ticks;
 }