Пример #1
0
        public static SoapException BuildWcfException <TChannel>(ClientBase <TChannel> wcf, Exception ex)
            where TChannel : class
        {
            SoapException soapEx;

            try
            {
                soapEx = BuildSoapException(ex, ex.InnerException);
            }
            catch (Exception buildEx)
            {
                string exMsg = ex.Message;
                var    sb    = new StringBuilder();
                sb.AppendLine(exMsg);
                sb.AppendLine("================= wcf.abort() exception trace ===============");
                sb.AppendLine(buildEx.ToString());
                exMsg  = sb.ToString();
                soapEx = new SoapException("General Web Exception on: " + exMsg, XmlQualifiedName.Empty, ex);
            }

            try
            {
                if (wcf != null)
                {
                    wcf.Abort();
                }
            }
            catch (Exception abortEx)
            {
                soapEx = BuildSoapException(ex, abortEx);
            }

            return(soapEx);
        }
Пример #2
0
 public void CheckStatus2 <TClient>(ClientBase <TClient> clientBase) where TClient : class
 {
     lock (this)
     {
         if (++this.invokeCount == this.maxCount)
         {
             clientBase?.Abort();
         }
     }
 }
Пример #3
0
 public static void FecharProxy(ClientBase <T> proxy)
 {
     try
     {
         if (proxy.State != System.ServiceModel.CommunicationState.Faulted)
         {
             proxy.Close();
         }
         else
         {
             proxy.Abort();
         }
     }
     catch (Exception)
     {
         proxy.Abort();
         throw;
     }
 }
 /// <summary>
 /// Transitions proxy to closed state via Close() or Abort()
 /// dependently on current proxy state
 /// </summary>
 public static void CloseProxy <T>(this ClientBase <T> proxy) where T : class
 {
     try
     {
         if (proxy.State != CommunicationState.Closed &&
             proxy.State != CommunicationState.Faulted)
         {
             proxy.Close(); // may throw exception while closing
         }
         else
         {
             proxy.Abort();
         }
     }
     catch (CommunicationException)
     {
         proxy.Abort();
         throw;
     }
 }
Пример #5
0
 void CleanConnection <TChannel>(ClientBase <TChannel> c) where TChannel : class
 {
     if (c != null)
     {
         try
         {
             if (c.State != CommunicationState.Faulted)
             {
                 c.Close();
             }
         }
         catch
         {
             c.Abort();
         }
     }
 }
Пример #6
0
        /// <summary>调用</summary>
        public static async Task InvokeAsync <IWcfService>(this ClientBase <IWcfService> client, Func <IWcfService, Task> command)
            where IWcfService : class
        {
            var proxy = client.As <IWcfService>();

            client.InnerChannel.OperationTimeout = s_OperationTimeout;
            try
            {
                await command(proxy);

                client.Close();
            }
            catch
            {
                client.Abort();
                throw;
            }
        }
Пример #7
0
 public static void CerrarConexion <TChannel>(this ClientBase <TChannel> proxy) where TChannel : class
 {
     try
     {
         if (proxy.State == CommunicationState.Faulted)
         {
             proxy.Abort();
         }
         else
         {
             proxy.Close();
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
 }
Пример #8
0
 public static void SafeClose_ <T>(this ClientBase <T> client) where T : class
 {
     try
     {
         client.Close();
     }
     catch (Exception e)
     {
         e.AddErrorLog();
         try
         {
             client.Abort();
         }
         catch (Exception err)
         {
             err.AddErrorLog();
         }
     }
 }
Пример #9
0
        public static void SafeCloseExtension <T>(this ClientBase <T> proxy) where T : class
        {
            bool success = false;

            try
            {
                if (proxy?.State != CommunicationState.Faulted)
                {
                    proxy?.Close();
                    success = true;
                }
            }
            finally
            {
                if (!success)
                {
                    proxy?.Abort();
                }
            }
        }