} //end ATWSInterface /// <summary> /// Connects using the specified username and password. /// </summary> /// <param name="username">The username.</param> /// <param name="password">The password.</param> /// <exception cref="AutotaskNETException">Error getting zone information.</exception> public void Connect(string username, string password) { this._atws = new net.autotask.webservices.ATWS() { Url = Properties.Settings.Default.Autotask_Net_Webservices_ATWS }; net.autotask.webservices.ATWSZoneInfo zoneInfo = this._atws.getZoneInfo(username); if (zoneInfo.ErrorCode >= 0) { this._atws = new net.autotask.webservices.ATWS() { Url = zoneInfo.URL }; this._atws.Url = zoneInfo.URL; CredentialCache _cache = new CredentialCache { { new Uri(this._atws.Url), "BASIC", new NetworkCredential(username, password) } }; this._atws.Credentials = _cache; this.IsConnected = true; } else { throw new AutotaskNETException("Error getting zone information."); } }
/// <summary> /// Initializes a new instance of the <see cref="ATWSInterface" /> class. /// </summary> /// <param name="username">The username.</param> /// <param name="password">The password.</param> /// <exception cref="ArgumentException">Connection parameters are not defined.</exception> /// <exception cref="Exception"> /// Error getting zone information. /// Login Error. /// </exception> public ATWSInterface(string username, string password) { if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password)) { throw new ArgumentException("Connection parameters are not defined."); } this._atws = new net.autotask.webservices.ATWS() { Url = Properties.Settings.Default.Autotask_Net_Webservices_ATWS }; try { net.autotask.webservices.ATWSZoneInfo zoneInfo = this._atws.getZoneInfo(username); if (zoneInfo.ErrorCode >= 0) { this._atws = new net.autotask.webservices.ATWS() { Url = zoneInfo.URL }; this._atws.Url = zoneInfo.URL; CredentialCache _cache = new CredentialCache(); _cache.Add(new Uri(this._atws.Url), "BASIC", new NetworkCredential(username, password)); this._atws.Credentials = _cache; } else { throw new Exception("Error getting zone information."); } } catch (Exception ex) { throw new Exception("Login Error: " + ex.Message); } } //end WebService