/// <summary> /// Gets an available instance of the specific client. /// </summary> /// <returns>T.</returns> protected T CreateClient() { try { T instance = null; lock (PoolList) { bool valid = false; while (!valid) { if (PoolList.Count > 0) { var queueItem = PoolList.Dequeue(); valid = queueItem.Item2.CompareTo(DateTime.Now.AddSeconds(-270)) > 0 && GetClt(queueItem.Item1).State == CommunicationState.Opened; if (valid) { instance = queueItem.Item1; } else { DisposeClient(GetClt(queueItem.Item1)); } } else { break; } } } if (instance != null) { foreach (var key in WulkaContext.Current.Keys) { GetClt(instance).InnerChannel.AddToContext(key, WulkaContext.Current[key]); } } else { var contractType = GetContractType(); var discoC = DiscoCache.CreateDiscoCache(_discoUrl); discoC.ContractType = contractType; var binding = discoC.GetBinding(); var endpointAddress = discoC.GetEndPointAdress(); instance = CreateClientInternal(binding, endpointAddress, WulkaCredentials.Current); } return(instance); } catch (Exception e) { var msg = String.Format("Error Creating Client for {0}: {1}", GetContractType(), e); var ex = new DiscoProxyException(msg, e); Logger.Error(msg); Logger.Error(ex.GetCombinedMessages()); throw ex; } }
/// <summary> /// Creates the discovery cache. /// </summary> /// <returns>DiscoCache.</returns> public static DiscoCache CreateDiscoCache(string ecoSpaceUrl = null) { if (String.IsNullOrWhiteSpace(ecoSpaceUrl)) { ecoSpaceUrl = ConfigurationHelper.DiscoEndpoint; } if (Caches.ContainsKey(ecoSpaceUrl)) { return(Caches[ecoSpaceUrl]); } var c = new DiscoCache() { EcoSpaceUrl = ecoSpaceUrl }; Caches.Add(ecoSpaceUrl, c); return(c); }
/// <summary> /// Creates the specific client. /// </summary> /// <returns></returns> protected T CreateClient() { try { DiscoCache discoC = DiscoCache.CreateDiscoCache(); discoC.ContractType = GetContractType(); var binding = discoC.GetBinding(); var endpointAddress = discoC.GetEndPointAdress(); return(CreateClientInternal(binding, endpointAddress, WulkaCredentials.Current)); } catch (Exception e) { _logger.Error(e.GetCombinedMessages()); if (e.InnerException != null) { throw e.InnerException; } throw; } }