/// <summary> /// Initializes a new instance of this class with the specified <see cref="AuthorizationData"/>. /// </summary> /// <param name="authorizationData">Represents a user who intends to access the corresponding customer and account.</param> /// <param name="environment">Bing Ads API environment</param> public ServiceClient(AuthorizationData authorizationData, ApiEnvironment?environment) { if (authorizationData == null) { throw new ArgumentNullException("authorizationData"); } _authorizationData = authorizationData; _serviceClientFactory = ServiceClientFactoryFactory.CreateServiceClientFactory(); if (!_serviceClientFactory.SupportedServiceTypes.Contains(typeof(TService))) { throw new InvalidOperationException(ErrorMessages.ApiServiceTypeMustBeInterface); } if (environment == null) { var envSetting = HostingEnvironment.IsHosted ? WebConfigurationManager.AppSettings[EnvironmentAppSetting] : ConfigurationManager.AppSettings[EnvironmentAppSetting]; if (!Enum.TryParse(envSetting, out _environment)) { _environment = ApiEnvironment.Production; } } else { _environment = environment.Value; } _channelFactory = _serviceClientFactory.CreateChannelFactory <TService>(_environment); RefreshOAuthTokensAutomatically = true; }
/// <summary> /// Initializes a new instance of this class with the specified <see cref="AuthorizationData"/>. /// </summary> /// <param name="authorizationData">Represents a user who intends to access the corresponding customer and account.</param> /// <param name="environment">Bing Ads API environment</param> public ServiceClient(AuthorizationData authorizationData, ApiEnvironment?environment) { if (authorizationData == null) { throw new ArgumentNullException("authorizationData"); } _authorizationData = authorizationData; _serviceClientFactory = ServiceClientFactoryFactory.CreateServiceClientFactory(); if (!_serviceClientFactory.SupportedServiceTypes.Contains(typeof(TService))) { throw new InvalidOperationException(ErrorMessages.ApiServiceTypeMustBeInterface); } DetectApiEnvironment(authorizationData, environment); _channelFactory = _serviceClientFactory.CreateChannelFactory <TService>(_environment); RefreshOAuthTokensAutomatically = true; }