private void getNewAuthToken() { netForumXMLSoapClient xWebClient = null; string strAuthResult; String logMethodName = ".getNewAuthToken() - "; _log.Debug(logMethodName + "Begin Method"); try { _log.Debug(logMethodName + "Creating xWebClient."); xWebClient = new netForumXMLSoapClient(); _log.Debug(logMethodName + "successfully created xWebClient."); _log.Debug(logMethodName + "Authiencticating Client"); _authToken = xWebClient.Authenticate(Config.XWebLogin, Config.XWebPassword, out strAuthResult); _log.Info(logMethodName + "The current xWeb AuthToken being used by this application is: " + _authToken.Token); } catch (TimeoutException te) { _log.Error(logMethodName + "TimeoutException on xWeb service call. make sure endpoint is reachable and configured correctly.", te); if (!retryAuth(xWebClient)) { ProxyHelper.HandleServiceException(xWebClient); throw te; } } ////we do not want to retry these. These are errors that will not be fixed by a retry, i.e. invalid credentials //catch (FaultException fe) //{ // _log.Error(logMethodName + "There has been an error for an xWeb Auth operation: ", fe); // throw fe; //} catch (CommunicationException ce) { _log.Error(logMethodName + "CommunicationException on xWeb service call. make sure endpoint is reachable and configured correctly... this may be due to Token expiration", ce); if (!retryAuth(xWebClient)) { ProxyHelper.HandleServiceException(xWebClient); throw ce; } } finally { if (xWebClient.State != CommunicationState.Closed) { ProxyHelper.CloseChannel(xWebClient); } } _log.Debug(logMethodName + "End Method"); }
private static bool retryAuth(netForumXMLSoapClient xWebClient) { string strAuthResult; bool ret = false; for (int i = 0; i < Config.XWebRetryAttemps; i++) { _log.Error("Retrying authentication attempt#: " + i.ToString()); try { _authToken = xWebClient.Authenticate(Config.XWebLogin, Config.XWebPassword, out strAuthResult); } catch {} if (_authToken != null) { return(true); } Thread.Sleep(Config.XWebRetryWait); } return(ret); }