/// <summary> /// Прикачване на сертификат към заявката към Regix. Сертификатът се търси по сериен номер в инсталираните на сървъра сертификати. /// </summary> /// <param name="srv">Regix заявка</param> /// <param name="serialNo">Сериен номер на сертификат</param> public static void BindCertificates(RegiXEntryPointClient srv, string serialNo) { string certSerialNum = serialNo; X509Store store = new X509Store(StoreLocation.LocalMachine); store.Open(OpenFlags.MaxAllowed); X509Certificate2Collection cers = store.Certificates.Find(X509FindType.FindBySerialNumber, certSerialNum, false); if (cers.Count > 0) { X509Certificate2 pfx = cers[0]; srv.ClientCredentials.ClientCertificate.Certificate = pfx; } else { SLog.log("CERTIFICATE NOT FOUND: " + certSerialNum); } store.Close(); }
/// <summary> /// Изпълнение на заявка към Regix сървис /// </summary> /// <param name="xml">Параметри на справката</param> /// <param name="operation">Адрес на справката</param> /// <returns></returns> public static string GetRegixData(System.Xml.XmlElement xml, string operation) { string res = string.Empty; WSHttpBinding bind = new WSHttpBinding(); bind.Security.Mode = SecurityMode.Transport; bind.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate; bind.MaxReceivedMessageSize = 200000; bind.OpenTimeout = new TimeSpan(0, 5, 0); bind.SendTimeout = new TimeSpan(0, 5, 0); bind.ReceiveTimeout = new TimeSpan(0, 5, 0); bind.CloseTimeout = new TimeSpan(0, 5, 0); SLog.log("START Regix: { " + operation + " }"); try { EndpointAddress endp = new EndpointAddress(RegixUtils.RegixURL); RegiXEntryPointClient rgx_srv = new RegiXEntryPointClient(bind, endp); RegixUtils.BindCertificates(rgx_srv, RegixUtils.CertSerialNumber); RegixUtils.ConfirmCertificate(); ServiceRequestData rd = new ServiceRequestData(); rd.CallContext = new CallContext(); rd.CallContext.LawReason = "Закон за правната помощ"; rd.CallContext.ServiceURI = string.Empty; rd.CallContext.Remark = string.Empty; rd.CallContext.ServiceType = "2"; rd.CallContext.AdministrationName = "Национално Бюро за Правна Помощ"; rd.CallbackURL = string.Empty; rd.EIDToken = string.Empty; rd.EmployeeEGN = string.Empty; rd.Argument = xml; rd.Operation = operation; if (RegixUtils.IsDebug) { RegixUtils.SeriliazeForDebug(rd); } ServiceResultData all_data = rgx_srv.ExecuteSynchronous(rd); if (all_data == null) { return(RegixUtils.GetErrorString("Няма данни")); } else if (all_data.HasError) { SLog.log(all_data.Error); return(RegixUtils.GetErrorString(all_data.Error)); } else { if (RegixUtils.IsDebug) { RegixUtils.SeriliazeForDebugResult(all_data); } if (all_data.Data != null && all_data.Data.Response != null) { res = all_data.Data.Response.Any.OuterXml; } } } catch (Exception exIn) { SLog.log("ERROR Regix:"); SLog.log(exIn); res = RegixUtils.GetErrorString("Няма връзка с услугата"); } SLog.log("END Regix: { " + operation + " }"); return(res); }