private static ClientBase <T> InitialClient <T>(System.ServiceModel.ClientBase <T> client) where T : class
        {
            string pfxKeyPath = "";
            string cerKeyPath = "";

            try
            {
                string root = System.Web.HttpContext.Current.Server.MapPath("~");
                pfxKeyPath = root + "/bin/cert.pfx";
                cerKeyPath = root + "/bin/bitaServicebusCert.cer";
                client.ClientCredentials.ServiceCertificate.DefaultCertificate = new X509Certificate2(cerKeyPath);
                Log.Debug("bitaServicebusCert.cer load done");

                if (Configuration.GetInstance().IsLocalMachin())
                {
                    client.ClientCredentials.ClientCertificate.Certificate = new X509Certificate2(pfxKeyPath,
                                                                                                  "DpQXmjdDBJif2K76qaEkS", X509KeyStorageFlags.PersistKeySet);
                }
                else
                {
                    client.ClientCredentials.ClientCertificate.Certificate = new X509Certificate2(pfxKeyPath,
                                                                                                  "DpQXmjdDBJif2K76qaEkS", X509KeyStorageFlags.MachineKeySet);
                }
                Log.Debug("cert.pfx load done");
                client.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode =
                    X509CertificateValidationMode.None;
                Log.Debug("certificate mode set successfully!");

                return(client);
            }
            catch (CryptographicException ex)
            {
                Log.Error("Public or Private Key Not Found; Path:" + pfxKeyPath + " OR " + cerKeyPath);
                Log.Error(ex.StackTrace);
                Log.Debug(ex.Message);
                if (ex.InnerException != null)
                {
                    Log.Error(ex.InnerException.Message);
                    if (ex.InnerException.InnerException != null)
                    {
                        Log.Error(ex.InnerException.InnerException.Message);
                    }
                }
                throw new UserInterfaceException(1002, "خطای داخلی رخ داده است.");
            }
        }
        /// <summary>
        /// ErrorCode = 10001
        /// </summary>
        /// <param name="patteNoOrPlaque"></param>
        /// <param name="byPlaque"></param>
        /// <returns></returns>
        public static JsonResultWithObject <Patte> GetPatte(string patteNoOrPlaque, bool byPlaque)
        {
            JsonResultWithObject <Patte> response = new JsonResultWithObject <Patte>();

            try
            {
                try
                {
                    if (!byPlaque)
                    {
                        Patte existingPatte =
                            PatteRepository.GetInstance().FindByPatteSerial(patteNoOrPlaque);
                        response.isSuccess = true;
                        response.messages  = null;
                        response.result    = existingPatte;
                        return(response);
                    }
                }
                catch (Exception)
                {
                    //do nothing because it means that this patte not found in dataBase.
                }

                GetCustomsPermitClient client = (GetCustomsPermitClient)InitialClient(new GetCustomsPermitClient());
                customsPermit          resp;
                if (byPlaque)
                {
                    resp = client.getCustomsPermitByPlaque(patteNoOrPlaque);
                }
                else
                {
                    resp = client.getCustomsPermitByCustomsPermitNumber(patteNoOrPlaque.Trim());
                }


                Patte patte = Patte.ConvertToPatte(resp);
                //GetBillOfLading(patte.Driver.NationalCode);
                if (!Configuration.GetInstance().IsLocalMachin())
                {
                    PatteRepository.GetInstance().Save(patte);
                }

                response.isSuccess = true;
                response.messages  = null;
                response.result    = patte;

                return(response);
            }
            catch (EndpointNotFoundException epe)
            {
                Log.Error("Service can not connect Bita.");
                response.messages = new object[] { "1003 خطا در ارتباط با سامانه های همکار." };
            }
            catch (UserInterfaceException ex)
            {
                Log.Error(ex.Message);
                response.messages = new[] { ex.Message };
            }
            catch (Exception ex)
            {
                Log.Error("خطای داخلی در دریافت پته 10001");
                Log.Error(ex.Message);
                response.messages = new object[] { "اطلاعات پته درخواستی نامعتبر و یا هنوز در گمرک دریافت نشده است." };
            }
            response.isSuccess = false;
            return(response);
        }