using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.ServiceModel; using System.Configuration; using System.ServiceModel.Description; using DataLibrary; using System.Net; using CoreSavingLibrary.WcfNShrlon; using CoreSavingLibrary.WcfNCommon; using CoreSavingLibrary.WcfNAccount; using CoreSavingLibrary.WcfNAdmin; using CoreSavingLibrary.WcfNAgency; using CoreSavingLibrary.WcfNBudget; using CoreSavingLibrary.WcfNBusscom; using CoreSavingLibrary.WcfNDeposit; using CoreSavingLibrary.WcfNDivavg; using CoreSavingLibrary.WcfNFinance; using CoreSavingLibrary.WcfNInvestment; using CoreSavingLibrary.WcfNKeeping; using CoreSavingLibrary.WcfNMis; using CoreSavingLibrary.WcfNPm; using CoreSavingLibrary.WcfNPrincipalBalance; using CoreSavingLibrary.WcfNTrading; namespace CoreSavingLibrary { public class WcfCalling { private XmlConfigService xml; public WcfCalling(XmlConfigService xml) { this.xml = xml; } private bool AcceptAllCertifications(object sender, System.Security.Cryptography.X509Certificates.X509Certificate certification, System.Security.Cryptography.X509Certificates.X509Chain chain, System.Net.Security.SslPolicyErrors sslPolicyErrors) { return true; } private bool progressBar = false; public bool ProgressBar { get { return progressBar; } set { progressBar = value; } } // PB125 ---------------------------------------------------------------------- private n_shrlonClient nShrlon; public n_shrlonClient NShrlon { get { if (nShrlon == null) { nShrlon = new n_shrlonClient(); SetBindingPB(nShrlon.Endpoint); nShrlon.Open(); } return nShrlon; } } private n_commonClient nCommon; public n_commonClient NCommon { get { if (nCommon == null) { nCommon = new n_commonClient(); SetBindingPB(nCommon.Endpoint); nCommon.Open(); } return nCommon; } } private n_accountClient nAccount; public n_accountClient NAccount { get { if (nAccount == null) { nAccount = new n_accountClient(); SetBindingPB(nAccount.Endpoint); nAccount.Open(); } return nAccount; } } private n_adminClient nAdmin; public n_adminClient NAdmin { get { if (nAdmin == null) { nAdmin = new n_adminClient(); SetBindingPB(nAdmin.Endpoint); nAdmin.Open(); } return nAdmin; } } private n_agencyClient nAgency; public n_agencyClient NAgency { get { if (nAgency == null) { nAgency = new n_agencyClient(); SetBindingPB(nAgency.Endpoint); nAgency.Open(); } return nAgency; } } private n_budgetClient nBudget; public n_budgetClient NBudget { get { if (nBudget == null) { nBudget = new n_budgetClient(); SetBindingPB(nBudget.Endpoint); nBudget.Open(); } return nBudget; } } private n_busscomClient nBusscom; public n_busscomClient NBusscom { get { if (nBusscom == null) { nBusscom = new n_busscomClient(); SetBindingPB(nBusscom.Endpoint); nBusscom.Open(); } return nBusscom; } } private n_depositClient nDeposit; public n_depositClient NDeposit { get { if (nDeposit == null) { nDeposit = new n_depositClient(); SetBindingPB(nDeposit.Endpoint); nDeposit.Open(); } return nDeposit; } } private n_divavgClient nDivavg; public n_divavgClient NDivavg { get { if (nDivavg == null) { nDivavg = new n_divavgClient(); SetBindingPB(nDivavg.Endpoint); nDivavg.Open(); } return nDivavg; } } private n_financeClient nFinance; public n_financeClient NFinance { get { if (nFinance == null) { nFinance = new n_financeClient(); SetBindingPB(nFinance.Endpoint); nFinance.Open(); } return nFinance; } } private n_investmentClient nInvestment; public n_investmentClient NInvestment { get { if (nInvestment == null) { nInvestment = new n_investmentClient(); SetBindingPB(nInvestment.Endpoint); nInvestment.Open(); } return nInvestment; } } private n_keepingClient nKeeping; public n_keepingClient NKeeping { get { if (nKeeping == null) { nKeeping = new n_keepingClient(); SetBindingPB(nKeeping.Endpoint); nKeeping.Open(); } return nKeeping; } } private n_misClient nMis; public n_misClient NMis { get { if (nMis == null) { nMis = new n_misClient(); SetBindingPB(nMis.Endpoint); nMis.Open(); } return nMis; } } private n_pmClient nPm; public n_pmClient NPm { get { if (nPm == null) { nPm = new n_pmClient(); SetBindingPB(nPm.Endpoint); nPm.Open(); } return nPm; } } private n_principalbalanceClient nPrincipalBalance; public n_principalbalanceClient NPrincipalBalance { get { if (nPrincipalBalance == null) { nPrincipalBalance = new n_principalbalanceClient(); SetBindingPB(nPrincipalBalance.Endpoint); nPrincipalBalance.Open(); } return nPrincipalBalance; } } private n_tradingClient nTrading; public n_tradingClient NTrading { get { if (nTrading == null) { nTrading = new n_tradingClient(); SetBindingPB(nTrading.Endpoint); nTrading.Open(); } return nTrading; } } //utility ---------------------------------------------------------------------- private void SetBindingPB(ServiceEndpoint endpoint) { BasicHttpBinding binding = new BasicHttpBinding(); binding.MaxReceivedMessageSize = Convert.ToInt64(ConfigurationManager.AppSettings["bindingMaxReceivedMessageSize"]); binding.ReaderQuotas.MaxDepth = Convert.ToInt32(ConfigurationManager.AppSettings["bindingReaderQuotasMaxDepth"]); binding.ReaderQuotas.MaxStringContentLength = Convert.ToInt32(ConfigurationManager.AppSettings["bindingReaderQuotasMaxStringContentLength"]); binding.ReaderQuotas.MaxArrayLength = Convert.ToInt32(ConfigurationManager.AppSettings["bindingReaderQuotasMaxArrayLength"]); binding.ReaderQuotas.MaxBytesPerRead = Convert.ToInt32(ConfigurationManager.AppSettings["bindingReaderQuotasMaxBytesPerRead"]); binding.CloseTimeout = TimeSpan.FromSeconds(Convert.ToInt32(ConfigurationManager.AppSettings["bindingCloseTimeout"])); binding.ReceiveTimeout = TimeSpan.FromSeconds(Convert.ToInt32(ConfigurationManager.AppSettings["bindingReceiveTimeout"])); binding.OpenTimeout = TimeSpan.FromSeconds(Convert.ToInt32(ConfigurationManager.AppSettings["bindingOpenTimeout"])); binding.SendTimeout = TimeSpan.FromSeconds(Convert.ToInt32(ConfigurationManager.AppSettings["bindingSendTimeout"])); endpoint.Binding = binding; // url Address string abUrl = endpoint.ListenUri.AbsoluteUri; string fileName = abUrl.Substring(abUrl.LastIndexOf("/") + 1); if (xml == null) { xml = new XmlConfigService(WebUtil.GetGcoopPath()); } String domain = xml.WcfPB125Domain; if (domain == "*") { domain = xml.SavDomain; } if (domain == "*") { domain = WebUtil.GetSavingAddress(); } String url = "http://" + domain + ":" + xml.WcfPB125Port + "/ICORE/" + xml.WcfPB125PathPattern; String uri = url + fileName; EndpointAddress enp = new EndpointAddress(new Uri(uri)); endpoint.Address = enp; } public void Close() { try { if (nShrlon != null) { nShrlon.Close(); nShrlon = null; } } catch { } try { if (nCommon != null) { nCommon.Close(); nCommon = null; } } catch { } try { if (nAccount != null) { nAccount.Close(); nAccount = null; } } catch { } try { if (nAdmin != null) { nAdmin.Close(); nAdmin = null; } } catch { } try { if (nAgency != null) { nAgency.Close(); nAgency = null; } } catch { } try { if (nBudget != null) { nBudget.Close(); nBudget = null; } } catch { } try { if (nBusscom != null) { nBusscom.Close(); nBusscom = null; } } catch { } try { if (nDeposit != null) { nDeposit.Close(); nDeposit = null; } } catch { } try { if (nDivavg != null) { nDivavg.Close(); nDivavg = null; } } catch { } try { if (nFinance != null) { nFinance.Close(); nFinance = null; } } catch { } try { if (nInvestment != null) { nInvestment.Close(); nInvestment = null; } } catch { } try { if (nKeeping != null) { nKeeping.Close(); nKeeping = null; } } catch { } try { if (nMis != null) { nMis.Close(); nMis = null; } } catch { } try { if (nPm != null) { nPm.Close(); nPm = null; } } catch { } try { if (nPrincipalBalance != null) { nPrincipalBalance.Close(); nPrincipalBalance = null; } } catch { } try { if (nTrading != null) { nTrading.Close(); nTrading = null; } } catch { } } private EndpointAddress ServiceUrl(String serviceName) { if (xml == null) { xml = new XmlConfigService(WebUtil.GetGcoopPath()); } if (xml.WcfProtocol == "https") { ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(new WcfCalling(null).AcceptAllCertifications); } String domain; if (ProgressBar) { domain = xml.WcfDomainProgress; } else { domain = xml.WcfDomain; } if (domain == "*") { domain = xml.SavDomain; } if (domain == "*") { domain = WebUtil.GetSavingAddress(); } String url = xml.WcfProtocol + "://" + domain + ":" + xml.WcfPort + "/ICORE/" + xml.WcfPathPattern; String uri = url + serviceName + ".svc"; EndpointAddress enp = new EndpointAddress(new Uri(uri)); return enp; } private void SetBinding(ServiceEndpoint endpoint, String name) { BasicHttpBinding binding = new BasicHttpBinding(); binding.MaxReceivedMessageSize = Convert.ToInt64(ConfigurationManager.AppSettings["bindingMaxReceivedMessageSize"]); binding.ReaderQuotas.MaxDepth = Convert.ToInt32(ConfigurationManager.AppSettings["bindingReaderQuotasMaxDepth"]); binding.ReaderQuotas.MaxStringContentLength = Convert.ToInt32(ConfigurationManager.AppSettings["bindingReaderQuotasMaxStringContentLength"]); binding.ReaderQuotas.MaxArrayLength = Convert.ToInt32(ConfigurationManager.AppSettings["bindingReaderQuotasMaxArrayLength"]); binding.ReaderQuotas.MaxBytesPerRead = Convert.ToInt32(ConfigurationManager.AppSettings["bindingReaderQuotasMaxBytesPerRead"]); binding.CloseTimeout = TimeSpan.FromSeconds(Convert.ToInt32(ConfigurationManager.AppSettings["bindingCloseTimeout"])); binding.ReceiveTimeout = TimeSpan.FromSeconds(Convert.ToInt32(ConfigurationManager.AppSettings["bindingReceiveTimeout"])); binding.OpenTimeout = TimeSpan.FromSeconds(Convert.ToInt32(ConfigurationManager.AppSettings["bindingOpenTimeout"])); binding.SendTimeout = TimeSpan.FromSeconds(Convert.ToInt32(ConfigurationManager.AppSettings["bindingSendTimeout"])); endpoint.Binding = binding; endpoint.Address = ServiceUrl(name); } } }