示例#1
0
        private static bool QueryService(ILogger logger, string host, int port, string serviceName,
                                         string[] requiredContracts, int maxRoundTrips, out Int64 bestRoundTrip)
        {
            bestRoundTrip = TimeSpan.FromSeconds(30).Ticks;
            AddressBinding addressBinding = WcfHelper.CreateAddressBinding(
                WcfConst.NetTcp, host, port, serviceName, typeof(IDiscoverV111).Name);

            try
            {
                using (var client = new DiscoverSenderV111(addressBinding))
                {
                    // query service n times to find best round trip
                    int loop = 0;
                    while (loop < maxRoundTrips)
                    {
                        DateTimeOffset    clientTime1 = DateTimeOffset.Now;
                        V111DiscoverReply reply       = client.DiscoverServiceV111();
                        // fail if server does not support required contracts
                        if (requiredContracts != null)
                        {
                            foreach (string requiredContract in requiredContracts)
                            {
                                if (reply.SupportedContracts == null)
                                {
                                    logger.LogDebug("Server ({0}) does not support contract: '{1}'", addressBinding.Address.Uri.AbsoluteUri, requiredContract);
                                    return(false);
                                }
                                bool supportsContract = false;
                                foreach (string supportedContract in reply.SupportedContracts)
                                {
                                    if (supportedContract == requiredContract)
                                    {
                                        supportsContract = true;
                                    }
                                }
                                if (!supportsContract)
                                {
                                    logger.LogDebug("Server ({0}) does not support contract: '{1}'", addressBinding.Address.Uri.AbsoluteUri, requiredContract);
                                    return(false);
                                }
                            }
                        }
                        // all required contracts supported
                        DateTimeOffset clientTime2 = DateTimeOffset.Now;
                        Int64          roundTrip   = clientTime2.Ticks - clientTime1.Ticks;
                        if ((roundTrip >= 0) && (roundTrip < bestRoundTrip))
                        {
                            bestRoundTrip = roundTrip;
                        }
                        // loop
                        loop++;
                    }
                    //logger.LogDebug("Server ({0}) answered ({1} ticks)", addressBinding.Address.Uri.AbsoluteUri, bestRoundTrip);
                    return(true);
                }
            }
            catch (EndpointNotFoundException)
            {
                //logger.LogDebug("Server ({0}) not answering.", addressBinding.Address.Uri.AbsoluteUri);
                return(false);
            }
            catch (CommunicationObjectFaultedException)
            {
                //logger.LogDebug("Server ({0}) not answering.", addressBinding.Address.Uri.AbsoluteUri);
                return(false);
            }
            //catch (Exception excp)
            //{
            //    logger.LogError("Server ({0}) threw exception: {1}", addressBinding.Address.Uri.AbsoluteUri, excp);
            //    return false;
            //}
        }
示例#2
0
 public DiscoverSenderV111(AddressBinding addressBinding)
     : base(addressBinding)
 {
 }
示例#3
0
 public CustomClientBase(AddressBinding addressBinding)
     : base(addressBinding.Binding, addressBinding.Address)
 {
 }
示例#4
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="addressBinding"></param>
 public SessCtrlSenderV131(AddressBinding addressBinding)
     : base(addressBinding)
 {
 }
示例#5
0
 public TransferSenderV341(AddressBinding addressBinding)
     : base(addressBinding)
 {
 }