Example #1
0
        public ISferaService CurrentService()
		{
            try
            {
                if (_service == null || _service.State == CommunicationState.Faulted)
                {
                    if (_service != null && _service.State == CommunicationState.Faulted)
                        _service.Abort();
                    _service = new SferaServiceClient("SferaServiceCompact");
                    var sc = new SymmetricCryptography<TripleDESCryptoServiceProvider>(Login.Instance.Key, Login.Instance.IV);
                    if (_service.ClientCredentials != null)
                    {
                        _service.ClientCredentials.UserName.UserName = sc.Encrypt(Login.Instance.CurrentLogin().LoginName + "&" + Login.Instance.CurrentLogin().CodiceAzienda);
                        _service.ClientCredentials.UserName.Password = sc.Encrypt(Login.Instance.CurrentLogin().Password);
                    }

                    // Il servizio non deve essere aperto:
                    // http://social.msdn.microsoft.com/Forums/vstudio/en-US/7ac84925-4cef-44fc-87aa-fa6fa366fa19/the-communication-object-channelfactory-cannot-be-modified-while-it-is-in-the-opened-state
//                    _service.Open();
                retry:
                    if (_service.State == CommunicationState.Opening)
                        goto retry;

                }
                return _service; 
            }
            catch (Exception ex)
            {
                var log = LogManager.GetLogger("Sfera");
                log.FatalFormat("Errore nella creazione del servizio - {0} - azienda:{1}", ex, Library.Utility.GetMethodDescription(), Login.Instance.CurrentLogin().Azienda);
                throw;
            }
		}
Example #2
0
 /// <summary>
 /// Private constructor to enforce singleton
 /// </summary>
 private SferaServiceProxy() 
 {
     try
     {
         _service = new SferaServiceClient("SferaServiceCompact");
         if (_service.ClientCredentials != null)
         {
             try
             {
                 _service.ClientCredentials.UserName.UserName = Login.Instance.CurrentLogin().EncryptLoginName;
                 _service.ClientCredentials.UserName.Password = Login.Instance.CurrentLogin().EncryptPassword;
             }
             catch (Exception ex)
             {
                 _log.FatalFormat("Errore nell'inizializzazione del proxy - IMPOSTAZIONE USERNAME E PASSWORD - {0} - username:{1} - password:{2}", ex, Library.Utility.GetMethodDescription(), Login.Instance.CurrentLogin().LoginName, Login.Instance.CurrentLogin().Password);
                 throw;
             }
         }
     }
     catch (Exception ex)
     {
         _log.FatalFormat("Errore nell'inizializzazione del proxy - {0}", ex, Library.Utility.GetMethodDescription());
         throw;
     }
 }
Example #3
0
 private void openService()
 {
     try
     {
         _service = new SferaServiceClient("SferaServiceCompact");
         var sc = new SymmetricCryptography<TripleDESCryptoServiceProvider>(Login.Instance.Key, Login.Instance.IV);
         if (_service.ClientCredentials != null)
         {
             _service.ClientCredentials.UserName.UserName = sc.Encrypt(Login.Instance.CurrentLogin().LoginName + "&" + Login.Instance.CurrentLogin().CodiceAzienda);
             _service.ClientCredentials.UserName.Password = sc.Encrypt(Login.Instance.CurrentLogin().Password);
         }
         _service.Open();
     }
     catch (Exception ex)
     {
         _log.FatalFormat("Errore nell'apertura del servizio - {0}", ex, Gipasoft.Library.Utility.GetMethodDescription());
         throw;
     }
 }
Example #4
0
 private void openService()
 {
     _service = new SferaServiceClient("SferaServiceCompact");
     Gipasoft.Security.SymmetricCryptography<TripleDESCryptoServiceProvider> sc = new Gipasoft.Security.SymmetricCryptography<TripleDESCryptoServiceProvider>(Gipasoft.Security.Login.Instance.Key, Gipasoft.Security.Login.Instance.IV);
     _service.ClientCredentials.UserName.UserName = sc.Encrypt("giorgio&zeth");
     _service.ClientCredentials.UserName.Password = sc.Encrypt("gipasoft");
     _service.Open();
 }
Example #5
0
        private SferaServiceClient getServiceClient()
        {
            if (_client == null)
            {
                _client = new SferaServiceClient("SferaServiceCompact");
                if (_client.ClientCredentials != null)
                {
                    _client.ClientCredentials.UserName.UserName = ConfigurationManager.AppSettings["LoginUser"];
                    _client.ClientCredentials.UserName.Password = ConfigurationManager.AppSettings["LoginPwd"];
                }
            }

            if (_client.State != CommunicationState.Opened)
            {
                _client = new SferaServiceClient("SferaServiceCompact");
                if (_client.ClientCredentials != null)
                {
                    _client.ClientCredentials.UserName.UserName = ConfigurationManager.AppSettings["LoginUser"];
                    _client.ClientCredentials.UserName.Password = ConfigurationManager.AppSettings["LoginPwd"];
                }
                _client.Open();
                while (_client.State != CommunicationState.Opened)
                {
                    var x = string.Empty;
                }
            }

            return _client;
        }
Example #6
0
 public void Close()
 {
     try
     {
         if (_service != null)
         {
             if (_service.State != CommunicationState.Faulted)
             {
                 _service.Close();
             }
             else
             {
                 _service.Abort();
             }
         }
     }
     catch (CommunicationException)
     {
         if (_service != null) 
             _service.Abort();
     }
     catch (TimeoutException)
     {
         if (_service != null)
             _service.Abort();
     }
     catch (Exception)
     {
         if (_service != null)
             _service.Abort();
         throw;
     }
     finally
     {
         _service = null;
     }
 }