Free cookie consent management tool by TermsFeed Policy Generator

Changeset 5527


Ignore:
Timestamp:
02/21/11 17:37:20 (14 years ago)
Author:
cneumuel
Message:

#1298

  • removed caching of ChannelFactory as this leeds to session timeouts (factory needs to be disposed properly)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Clients.Common/3.3/ClientFactory.cs

    r5445 r5527  
    2222using System;
    2323using System.ServiceModel;
     24using System.ServiceModel.Description;
    2425using HeuristicLab.Clients.Common.Properties;
    25 using System.ServiceModel.Description;
    26 using System.Collections;
    27 using System.Collections.Generic;
    2826using HeuristicLab.Common;
    2927
     
    6563    }
    6664
    67     public static Disposable<I> CreateClient<I>(string endpointConfigurationName) where I : class {
    68       return CreateClient<I>(endpointConfigurationName, null);
     65    public static Disposable<ChannelFactory<I>> CreateChannelFactory<I>(string endpointConfigurationName) where I : class {
     66      return CreateChannelFactory<I>(endpointConfigurationName, null);
    6967    }
    70     public static Disposable<I> CreateClient<I>(string endpointConfigurationName, string remoteAddress) where I : class {
    71       return CreateClient<I>(endpointConfigurationName, remoteAddress, Settings.Default.UserName, Settings.Default.Password);
     68    public static Disposable<ChannelFactory<I>> CreateChannelFactory<I>(string endpointConfigurationName, string remoteAddress) where I : class {
     69      return CreateChannelFactory<I>(endpointConfigurationName, remoteAddress, Settings.Default.UserName, Settings.Default.Password);
    7270    }
    73     public static Disposable<I> CreateClient<I>(string endpointConfigurationName, string remoteAddress, string userName, string password) where I : class {
     71    public static Disposable<ChannelFactory<I>> CreateChannelFactory<I>(string endpointConfigurationName, string remoteAddress, string userName, string password) where I : class {
    7472      ChannelFactory<I> factory = GetChannelFactory<I>(endpointConfigurationName, userName, password);
    7573
     
    7775        SetEndpointAddress(factory.Endpoint, remoteAddress);
    7876      }
    79       Disposable<I> disposable = new Disposable<I>(factory.CreateChannel());
     77      var disposable = new Disposable<ChannelFactory<I>>(factory);
    8078      disposable.OnDisposing += new EventHandler<EventArgs<object>>(disposable_OnDisposing);
    81 
    8279      return disposable;
    8380    }
     
    8885    }
    8986
    90     private static IDictionary<ChannelProperties, ChannelFactory> channelFactoryCache = new Dictionary<ChannelProperties, ChannelFactory>();
    9187    private static ChannelFactory<I> GetChannelFactory<I>(string endpointConfigurationName, string userName, string password) where I : class {
    92       ChannelProperties key = new ChannelProperties(typeof(I), endpointConfigurationName, userName, password);
    93       if (!channelFactoryCache.ContainsKey(key)) {
    94         channelFactoryCache.Add(key, new ChannelFactory<I>(endpointConfigurationName));
    95         channelFactoryCache[key].Credentials.UserName.UserName = userName;
    96         channelFactoryCache[key].Credentials.UserName.Password = password;
    97         channelFactoryCache[key].Credentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None;
    98       }
    99       return (ChannelFactory<I>)channelFactoryCache[key];
     88      var channelFactory = new ChannelFactory<I>(endpointConfigurationName);
     89      channelFactory.Credentials.UserName.UserName = userName;
     90      channelFactory.Credentials.UserName.Password = password;
     91      channelFactory.Credentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None;
     92      return channelFactory;
    10093    }
    10194
     
    122115    }
    123116  }
    124 
    125   internal struct ChannelProperties {
    126     public Type type;
    127     public string endpointConfigurationName;
    128     public string userName;
    129     public string password;
    130 
    131     public ChannelProperties(Type type, string endpointConfigurationName, string userName, string password) {
    132       this.type = type;
    133       this.endpointConfigurationName = endpointConfigurationName;
    134       this.userName = userName;
    135       this.password = password;
    136     }
    137   }
    138117}
Note: See TracChangeset for help on using the changeset viewer.