コード例 #1
0
ファイル: Comprobante.cs プロジェクト: pjeconde/eFact
        public string EnviarIBK(FeaEntidades.InterFacturas.lote_comprobantes lc, string certificado)
        {
            IBK.lote_comprobantes lcIBK = new IBK.lote_comprobantes();
            lcIBK = Fea2Ibk(lc);

            IBK.FacturaWebServiceConSchema objIBK;
            objIBK = new IBK.FacturaWebServiceConSchema();
            objIBK.Url = System.Configuration.ConfigurationManager.AppSettings["URLinterfacturas"];
            if (System.Configuration.ConfigurationManager.AppSettings["Proxy"] != null && System.Configuration.ConfigurationManager.AppSettings["Proxy"] != "")
            {
                System.Net.WebProxy wp = new System.Net.WebProxy(System.Configuration.ConfigurationManager.AppSettings["Proxy"], false);
                string usuarioProxy = System.Configuration.ConfigurationManager.AppSettings["UsuarioProxy"];
                string claveProxy = System.Configuration.ConfigurationManager.AppSettings["ClaveProxy"];
                string dominioProxy = System.Configuration.ConfigurationManager.AppSettings["DominioProxy"];

                System.Net.NetworkCredential networkCredential = new System.Net.NetworkCredential(usuarioProxy, claveProxy, dominioProxy);
                wp.Credentials = networkCredential;
                objIBK.Proxy = wp;
            }

            X509Store store = new X509Store(StoreLocation.LocalMachine);
            store.Open(OpenFlags.ReadOnly);
            X509Certificate2Collection col = store.Certificates.Find(X509FindType.FindBySerialNumber, certificado, true);
            if (col.Count.Equals(1))
            {
                objIBK.ClientCertificates.Add(col[0]);
                System.Threading.Thread.Sleep(1000);
                IBK.lote_comprobantes_response lcr = objIBK.receiveFacturasConSchema(lcIBK);

                string resultado = string.Empty;

                if (!((IBK.lote_response)(lcr.Item)).estado.Equals("OK"))
                {
                    if (((IBK.lote_response)lcr.Item).errores_lote != null)
                    {
                        resultado = ((IBK.lote_response)lcr.Item).errores_lote[0].descripcion_error;
                    }
                    else
                    {
                        resultado = ((IBK.lote_response)lcr.Item).comprobante_response[0].errores_comprobante[0].descripcion_error;
                    }
                    throw new Exception(resultado);
                }
                else
                {
                    resultado = "Comprobante enviado satisfactoriamente a Interfacturas";
                }
                return resultado;
            }
            else
            {
                throw new Exception("Su certificado no está disponible en nuestro repositorio");
            }
        }
コード例 #2
0
ファイル: Comprobante.cs プロジェクト: pjeconde/eFact
        public FeaEntidades.InterFacturas.lote_comprobantes ConsultarIBK(IBK.consulta_lote_comprobantes clc, string certificado)
        {
            FeaEntidades.InterFacturas.lote_comprobantes lc = new FeaEntidades.InterFacturas.lote_comprobantes();
            lc.cabecera_lote = new FeaEntidades.InterFacturas.cabecera_lote();
            lc.comprobante = new FeaEntidades.InterFacturas.comprobante[1];
            IBK.FacturaWebServiceConSchema objIBK;
			objIBK = new IBK.FacturaWebServiceConSchema();
            objIBK.Url = System.Configuration.ConfigurationManager.AppSettings["URLinterfacturas"];
            if (System.Configuration.ConfigurationManager.AppSettings["Proxy"] != null)
            {
                System.Net.WebProxy wp = new System.Net.WebProxy(System.Configuration.ConfigurationManager.AppSettings["Proxy"], false);
                string usuarioProxy = System.Configuration.ConfigurationManager.AppSettings["UsuarioProxy"];
                string claveProxy = System.Configuration.ConfigurationManager.AppSettings["ClaveProxy"];
                string dominioProxy = System.Configuration.ConfigurationManager.AppSettings["DominioProxy"];
                System.Net.NetworkCredential networkCredential = new System.Net.NetworkCredential(usuarioProxy, claveProxy, dominioProxy);
                wp.Credentials = networkCredential;
                objIBK.Proxy = wp;
            }
            X509Store store = new X509Store(StoreLocation.LocalMachine);
            store.Open(OpenFlags.ReadOnly);
            X509Certificate2Collection col = store.Certificates.Find(X509FindType.FindBySerialNumber, certificado, true);
            if (col.Count.Equals(1))
            {
                objIBK.ClientCertificates.Add(col[0]);
                System.Threading.Thread.Sleep(1000);
                IBK.consulta_lote_comprobantes_response clcr = objIBK.getLoteFacturasConSchema(clc);
                IBK.consulta_lote_response clr;
                try
                {
                    clr = (IBK.consulta_lote_response)clcr.Item;
                    IBK.lote_comprobantes lcIBK = (IBK.lote_comprobantes)clr.Item;
                    lc = Ibk2Fea(lcIBK);
                }
                catch (InvalidCastException)
                {
                    StringBuilder errorText = new StringBuilder();
                    if (clcr.Item != null)
                    {
                        errorText.Append("Nro. de Lote: [" + clc.id_lote + "]\r\n");
                        if (clcr.Item.GetType() == typeof(IBK.consulta_lote_response))
                        {
                            clr = (IBK.consulta_lote_response)clcr.Item;
                            IBK.consulta_lote_responseErrores_consulta errores = (IBK.consulta_lote_responseErrores_consulta)clr.Item;
                            foreach (IBK.error elote in errores.error)
                            {
                                errorText.Append(elote.codigo_error + " - " + elote.descripcion_error + "\r\n");
                            }
                        }
                        else
                        {
                            IBK.consulta_lote_comprobantes_responseErrores_response clcrEr;
                            clcrEr = (IBK.consulta_lote_comprobantes_responseErrores_response)clcr.Item;
                            foreach (IBK.error elote in clcrEr.error)
                            {
                                errorText.Append(elote.codigo_error + " - " + elote.descripcion_error + "\r\n");
                            }
                        }
                    }
                    throw new Exception(errorText.ToString());
                }
                return lc;
            }
            else
            {
                throw new Exception("Su certificado no está disponible en nuestro repositorio");
            }
        }
コード例 #3
0
ファイル: Comprobante.cs プロジェクト: pjeconde/eFact
        public void EnviarIBK(out CedWebRN.IBK.lote_response Lr, FeaEntidades.InterFacturas.lote_comprobantes lc, string certificado)
        {
            IBK.lote_comprobantes lcIBK = new IBK.lote_comprobantes();
            lcIBK = Fea2Ibk(lc);
			IBK.FacturaWebServiceConSchema objIBK;
			objIBK = new IBK.FacturaWebServiceConSchema();
            objIBK.Url = System.Configuration.ConfigurationManager.AppSettings["URLinterfacturas"];
            objIBK.Timeout = 3900000;
            if (System.Configuration.ConfigurationManager.AppSettings["Proxy"] != null && System.Configuration.ConfigurationManager.AppSettings["Proxy"] != "")
            {
                System.Net.WebProxy wp = new System.Net.WebProxy(System.Configuration.ConfigurationManager.AppSettings["Proxy"], false);
                string usuarioProxy = System.Configuration.ConfigurationManager.AppSettings["UsuarioProxy"];
                string claveProxy = System.Configuration.ConfigurationManager.AppSettings["ClaveProxy"];
                string dominioProxy = System.Configuration.ConfigurationManager.AppSettings["DominioProxy"];
                System.Net.NetworkCredential networkCredential = new System.Net.NetworkCredential(usuarioProxy, claveProxy, dominioProxy);
                wp.Credentials = networkCredential;
                objIBK.Proxy = wp;
            }
            string storeLocation = System.Configuration.ConfigurationManager.AppSettings["StoreLocation"];
            X509Store store;
            if (storeLocation == "CurrentUser")
            {
                store = new X509Store(StoreLocation.CurrentUser);
            }
            else 
            {
                store = new X509Store(StoreLocation.LocalMachine);
            }
            store.Open(OpenFlags.ReadOnly);
            X509Certificate2Collection col = store.Certificates.Find(X509FindType.FindBySerialNumber, certificado, true);
            if (col.Count.Equals(1))
            {
                //objIBK.RequestEncoding = System.Text.Encoding.GetEncoding("iso-8859-1");
                objIBK.ClientCertificates.Add(col[0]);
                System.Threading.Thread.Sleep(1000);
                IBK.lote_comprobantes_response lcr = objIBK.receiveFacturasConSchema(lcIBK);
                IBK.lote_response lr = new CedWebRN.IBK.lote_response();
                try
                {
                    lr = ((IBK.lote_response)lcr.Item);
                    if (lr.estado == "OK")
                    {
                        Lr = lr;
                    }
                    else
                    {
                        Lr = lr;
                        StringBuilder errorText = new StringBuilder();
                        if (Lr.errores_lote != null)
                        {
                            errorText.Append("Nro. de Lote: [" + Lr.id_lote + "] \r\n");
                            foreach (CedWebRN.IBK.error elote in Lr.errores_lote)
                            {
                                errorText.Append(elote.codigo_error + " - " + elote.descripcion_error + " \r\n");
                            }
                        }
                        if (Lr.comprobante_response != null)
                        {
                            foreach (CedWebRN.IBK.comprobante_response comprobante in Lr.comprobante_response)
                            {
                                if (comprobante.errores_comprobante != null)
                                {
                                    if (Lr.errores_lote != null)
                                    {
                                        errorText.Append("\r\n");
                                    }
                                    errorText.Append("Punto de Venta: [" + comprobante.punto_de_venta + "]  Tipo de Comprobante: [" + comprobante.tipo_de_comprobante + "]  Nro. de Comprobante: [" + comprobante.numero_comprobante + "] \r\n");
                                    foreach (CedWebRN.IBK.error ecomprobante in comprobante.errores_comprobante)
                                    {
                                        errorText.Append(ecomprobante.codigo_error + " - " + ecomprobante.descripcion_error + " \r\n");
                                    }
                                }
                            }
                        }
                        throw new Microsoft.ApplicationBlocks.ExceptionManagement.Validaciones.Lote.ProblemasEnvio(errorText.ToString());
                    }
                }
                catch (InvalidCastException)
                {
                    StringBuilder errorText = new StringBuilder();
                    if (lcr.Item != null)
                    {
                        if (lcr.Item.GetType() == typeof(IBK.lote_comprobantes_responseErrores_response))
                        {
                            IBK.lote_comprobantes_responseErrores_response lcrEr = new CedWebRN.IBK.lote_comprobantes_responseErrores_response();
                            errorText.Append("Nro. de Lote: [" + lc.cabecera_lote.id_lote + "] \r\n");
                            lcrEr = (IBK.lote_comprobantes_responseErrores_response)lcr.Item;
                            foreach (IBK.error error in lcrEr.error)
                            {
                                errorText.Append(error.codigo_error + " - " + error.descripcion_error + " \r\n");
                            }
                        }
                    }
                    throw new Exception(errorText.ToString());
                }
            }
            else
            {
                throw new Exception("Su certificado no está disponible en nuestro repositorio");
            }
        }