示例#1
0
        public Models.acumuladoresCreditoConsulta acumuladoresCreditoIndicativaWeb(Models.imputacionCreditoConsulta data)
        {
            try
            {
                //Limpieza codigo strings
                Functions.CheckStringFields(ref data);
            }
            catch (Exception ex)
            {
                log.Info(ex.Message);
            }

            log.Info(ServiceLogName + " - Ingreso");

            log.Debug(ServiceLogName + " - Seteando variables de contexto.");

            string usuarioProxy = Settings.GetAppSettings("Settings:Proxy:User");
            string passwdProxy  = Settings.GetAppSettings("Settings:Proxy:Password");
            string urlProxy     = Settings.GetAppSettings("Settings:Proxy:Url");
            string domainProxy  = Settings.GetAppSettings("Settings:Proxy:Domain");

            string usuarioWS = Settings.GetAppSettings("Settings:Service:User");
            string passwdWS  = Settings.GetAppSettings("Settings:Service:Password");

            string digitalMark = Settings.GetAppSettings("Settings:Credential:DigitalMark");

            string WSAction   = Settings.GetAppSettings("Settings:Service:Action");
            string WSEndpoint = Settings.GetAppSettings("Settings:Service:Endpoint");

            #region Consulta Servicio Gestion Claves
            //string passwdWS = string.Empty;
            //bool gestionClavesSuccess = true;
            //string gestionClavesMessage = string.Empty;

            //try
            //{
            //    log.Info("Inicio Servicio Gestion Claves");
            //    string gestionClavesEndpoint = ConfigurationManager.AppSettings["GClaves_Endpoint"];
            //    _gestionService.Endpoint.Address = new EndpointAddress(gestionClavesEndpoint);

            //    string gcUser = ConfigurationManager.AppSettings["GCLaves_USU"];
            //    string gcPass = ConfigurationManager.AppSettings["GCLaves_PSW"];

            //    string key = ConfigurationManager.AppSettings["GClaves_EsidifPass"];

            //    log.Info("Invocando al metodo ConsultarKey");
            //    string resultGC = _gestionService.ConsultarKey(gcUser, gcPass, key);

            //    if (!string.IsNullOrEmpty(resultGC) && resultGC.Length > 0)
            //    {
            //        log.Info("Invocacion a Gestion Claves Correcta");
            //        passwdWS = resultGC;
            //    }
            //    else
            //    {
            //        throw new Exception("El valor devuelto esta vacio");
            //    }

            //}
            //catch (Exception ex)
            //{
            //    gestionClavesSuccess = false;
            //    gestionClavesMessage = ex.Message;
            //    log.Info("Fallo la invocacion a Gestion Claves: " + ex.Message);
            //}

            //if (!gestionClavesSuccess)
            //{
            //    throw new Exception(gestionClavesMessage);
            //}
            #endregion

            log.Debug(ServiceLogName + " - Seteando PROXY.");
            WebProxy proxy = Functions.CreateProxy(usuarioProxy, passwdProxy, urlProxy, domainProxy);

            log.Debug(ServiceLogName + " - Cargando certificado X509.");
            NetworkCredential credential      = new NetworkCredential(usuarioWS, passwdWS);
            CredentialCache   credentialCache = new CredentialCache();
            credentialCache.Add(new Uri(WSEndpoint), "NTLM", credential);

            log.Debug(ServiceLogName + " - IGNORA_ERROR_CERTI = true.");
            ServicePointManager.ServerCertificateValidationCallback += RemoteCertificateValidationCallback;

            log.Debug(ServiceLogName + " - Certificado X509 cargado exitosamente.");

            log.Debug(ServiceLogName + " - Creando Bean");
            var envelope = new Envelope();
            envelope.Header = new Header("UsernameToken-1", usuarioWS, passwdWS, WSEndpoint, WSAction);
            envelope.Body   = new XmlAnything <IBody>(data);

            System.Xml.Serialization.XmlSerializerNamespaces xmlnsSoap = new System.Xml.Serialization.XmlSerializerNamespaces();
            xmlnsSoap.Add("soapenv", "http://schemas.xmlsoap.org/soap/envelope/");
            xmlnsSoap.Add("web", "http://webService.imputacionesPresupuestarias.esidif.mecon.gov.ar");
            xmlnsSoap.Add("wsse", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");
            xmlnsSoap.Add("wsu", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd");
            xmlnsSoap.Add("wsa", "http://www.w3.org/2005/08/addressing");

            log.Debug(ServiceLogName + " - Mapeando a objeto XML.");
            string msgRequest  = Functions.SerializeObjectToString(envelope, xmlnsSoap);
            string msgResponse = string.Empty;

            log.Debug(ServiceLogName + " - Armando header de autenticacion");
            HttpWebRequest request = WebRequest.Create(WSEndpoint) as HttpWebRequest;
            request.Headers.Add("SOAPAction", WSAction);
            request.ContentType         = "text/xml;charset=\"utf-8\"";
            request.Accept              = "text/xml";
            request.Method              = WebRequestMethods.Http.Post;
            request.KeepAlive           = true;
            request.PreAuthenticate     = true;
            request.AuthenticationLevel = AuthenticationLevel.MutualAuthRequested;
            request.Proxy       = proxy;
            request.Credentials = credentialCache;
            request.ClientCertificates.Add(Functions.GetClientCertificate(digitalMark));

            using (Stream stm = request.GetRequestStream())
            {
                using (StreamWriter stmw = new StreamWriter(stm))
                {
                    stmw.Write(msgRequest);
                }
            }

            log.Info("Consulta Servicio - ESIDIF : " + Environment.NewLine + Functions.ParseXml(msgRequest));
            WebResponse response = request.GetResponse();

            using (StreamReader reader = new StreamReader(response.GetResponseStream()))
            {
                msgResponse = reader.ReadToEnd();
            }

            log.Info("Respuesta ESIDIF - Servicio : " + Environment.NewLine + Functions.ParseXml(msgResponse));
            var resp = Functions.DeserializeXMLString <Models.acumuladoresCreditoConsulta>(msgResponse);

            return(resp);
        }
示例#2
0
        public Models.imputacionCreditoConsulta consultarLimitativaCredito(Models.consultarLimitativaCreditoRequest request)
        {
            Models.imputacionCreditoConsulta ret = new Models.imputacionCreditoConsulta();

            log.Info(ServiceLogName + " - Ingreso");
            var b = _service.Endpoint.Binding as CustomBinding;

            log.Debug(ServiceLogName + " - Seteando variables de contexto.");
            string usuarioProxy = ConfigurationManager.AppSettings["CPA_Proxy_Usuario"];
            string passwdProxy  = ConfigurationManager.AppSettings["CPA_Proxy_Passwd"];
            string urlProxy     = ConfigurationManager.AppSettings["CPA_Proxy_URL"];
            string domainProxy  = ConfigurationManager.AppSettings["CPA_Proxy_Dominio"];
            string digitalMark  = ConfigurationManager.AppSettings["CERTI_DIGITAL_MARK"];

            string usuarioWS = ConfigurationManager.AppSettings["WS_Usuario"];
            string passwdWS  = string.Empty;

            #region Consulta Servicio Gestion Claves -o- Configuracion
            bool usarGClaves = false;
            bool.TryParse(ConfigurationManager.AppSettings["GCLaves_Habilitado"], out usarGClaves);

            if (usarGClaves)
            {
                log.Info("Obteniendo datos desde Gestion Claves");
                bool   gestionClavesSuccess = true;
                string gestionClavesMessage = string.Empty;

                try
                {
                    log.Info("Inicio Servicio Gestion Claves");
                    string gestionClavesEndpoint = ConfigurationManager.AppSettings["GClaves_Endpoint"];
                    _gestionClavesService.Endpoint.Address = new EndpointAddress(gestionClavesEndpoint);

                    string gcUser = ConfigurationManager.AppSettings["GCLaves_USU"];
                    string gcPass = ConfigurationManager.AppSettings["GCLaves_PSW"];

                    string key = ConfigurationManager.AppSettings["GClaves_EsidifPass"];

                    log.Info("Invocando al metodo ConsultarKey");
                    string result = _gestionClavesService.ConsultarKey(gcUser, gcPass, key);

                    if (!string.IsNullOrEmpty(result) && result.Length > 0)
                    {
                        log.Info("Invocacion a Gestion Claves Correcta");
                        passwdWS = result;
                    }
                    else
                    {
                        throw new Exception("El valor devuelto esta vacio");
                    }
                }
                catch (Exception ex)
                {
                    gestionClavesSuccess = false;
                    gestionClavesMessage = ex.Message;
                    log.Info("Fallo la invocacion a Gestion Claves: " + ex.Message);
                }

                if (!gestionClavesSuccess)
                {
                    throw new Exception(gestionClavesMessage);
                }
            }
            else
            {
                log.Info("Obteniendo datos desde la configuracion");
                passwdWS = ConfigurationManager.AppSettings["WS_Password"];
            }

            #endregion

            log.Debug(ServiceLogName + " - Seteando PROXY.");
            HttpsTransportBindingElement httpsTransport = new HttpsTransportBindingElement();
            httpsTransport.ProxyAddress           = new Uri(urlProxy);
            httpsTransport.UseDefaultWebProxy     = false;
            httpsTransport.BypassProxyOnLocal     = false;
            httpsTransport.MaxReceivedMessageSize = 2147483647;

            if (ConfigurationManager.AppSettings["CERTI_IGNORA_ERROR"] == "true")
            {
                log.Debug(ServiceLogName + " - IGNORA_ERROR_CERTI = true.");
                System.Net.ServicePointManager.ServerCertificateValidationCallback += RemoteCertificateValidationCallback;
            }

            if (ConfigurationManager.AppSettings["CPA_Proxy_Credenciales"] == "true")
            {
                log.Debug(ServiceLogName + " - CPA_Proxy_Credenciales = true.");
                httpsTransport.ProxyAuthenticationScheme     = AuthenticationSchemes.Basic;
                _service.ClientCredentials.UserName.UserName = usuarioProxy;
                _service.ClientCredentials.UserName.Password = passwdProxy;
            }
            else
            {
                log.Debug(ServiceLogName + " - CPA_Proxy_Credenciales = false.");
                httpsTransport.ProxyAuthenticationScheme = AuthenticationSchemes.Ntlm;
            }

            b.Elements.Add(httpsTransport);

            if (ConfigurationManager.AppSettings["CERTI_APLICA"] == "true")
            {
                log.Debug(ServiceLogName + " - Cargando certificado X509.");
                _service.ClientCredentials.ClientCertificate.Certificate = Functions.GetClientCertificate(digitalMark);
                log.Debug(ServiceLogName + " - Certificado X509 cargado exitosamente.");
            }

            using (var scope = new OperationContextScope(_service.InnerChannel))
            {
                try
                {
                    log.Debug(ServiceLogName + " - Creando Bean");
                    var paramMecom = GenericClass <service.imputacionCreditoConsulta> .GenericMethod(); //service.imputacionCreditoConsulta.Create();

                    log.Debug(ServiceLogName + " - Mapeando a objeto MECON.");
                    Functions.CopyPropertiesTo(request.imputacionPresupuestariaCreditoIndicativa, paramMecom);

                    log.Debug(ServiceLogName + " - Armando header de autenticacion");
                    OperationContext.Current.OutgoingMessageHeaders.Add(new SecurityHeader("UsernameToken-1", usuarioWS, passwdWS));

                    _service.Endpoint.Address = new EndpointAddress(ConfigurationManager.AppSettings["WS_Endpoint"]);

                    var response = _service.consultarLimitativaCredito(paramMecom);

                    Functions.CopyPropertiesTo(response, ret);

                    return(ret);
                }
                catch (Exception ex)
                {
                    log.Error(ServiceLogName + " - Error en la ejecucion : " + ex.Message);
                    throw ex;
                }
            };
        }