Exemplo n.º 1
0
        public static void WriteLog(Action <Exception> action, string[] prms)
        {
            RFIDServiceClient client = null;

            try
            {
                string           remoteAddress = ReaderConfig.BuildUrl();
                EndpointAddress  endpoint      = new EndpointAddress(remoteAddress);
                BasicHttpBinding binding       = new BasicHttpBinding(BasicHttpSecurityMode.None);
                //binding.Security = BasicHttpSecurityMode.Transport;
                binding.OpenTimeout            = new TimeSpan(0, 0, 10);
                binding.CloseTimeout           = new TimeSpan(0, 0, 10);
                binding.SendTimeout            = new TimeSpan(0, 0, 10);
                binding.ReceiveTimeout         = new TimeSpan(0, 0, 10);
                binding.MaxReceivedMessageSize = int.MaxValue;
                binding.MaxBufferPoolSize      = int.MaxValue;
                binding.MaxBufferSize          = int.MaxValue;
                client = new RFIDServiceClient(binding, endpoint);

                client.WriteLog(prms);
                action(null);
            }
            catch (Exception e)
            {
                action(e);
            }
        }
Exemplo n.º 2
0
        public static void WriteLog(Action <Exception> action, string[] prms)
        {
            RFIDServiceClient client = null;

            try
            {
                client = new RFIDServiceClient();
                client.WriteLog(prms);
                action(null);
            }
            #region excption handling
            catch (CommunicationException e)
            {
                action(new Exception(string.Format("服务端程序发生内部错误,错误原因:{0}", e.Message)));
            }
            catch (TimeoutException)
            {
                action(new Exception("连接超时,请检查网络或者服务器状态!"));
            }
            catch (Exception e)
            {
                action(e);
            }
            finally
            {
                ICommunicationObject comObj = ((ICommunicationObject)client);

                if (comObj.State == CommunicationState.Faulted)
                {
                    comObj.Abort();
                }
                else
                {
                    comObj.Close();
                }
            }
            #endregion
        }