示例#1
0
        public static void EnviarIBK(out 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"];
            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 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("Lote Nro.: [" + Lr.id_lote + "] \r\n");
                            foreach (RN.IBK.error elote in Lr.errores_lote)
                            {
                                errorText.Append(elote.codigo_error + " - " + elote.descripcion_error + " \r\n");
                            }
                            errorText.Append("\r\n");
                        }
                        if (Lr.comprobante_response != null)
                        {
                            foreach (RN.IBK.comprobante_response comprobante in Lr.comprobante_response)
                            {
                                if (comprobante.errores_comprobante != null)
                                {
                                    errorText.Append("Nro. de Comprobante: [" + comprobante.numero_comprobante + "]  Punto de Venta: [" + comprobante.punto_de_venta + "]  Tipo de Comprobante: [" + comprobante.tipo_de_comprobante + "] \r\n");
                                    foreach (RN.IBK.error ecomprobante in comprobante.errores_comprobante)
                                    {
                                        errorText.Append(ecomprobante.codigo_error + " - " + ecomprobante.descripcion_error + " \r\n");
                                    }
                                }
                            }
                        }
                        throw new EX.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 RN.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");
            }
        }
示例#2
0
        public static 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;
            }
            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.ClientCertificates.Add(col[0]);
                System.Threading.Thread.Sleep(1000);
                IBK.lote_comprobantes_response lcr = objIBK.receiveFacturasConSchema(lcIBK);

                string resultado = string.Empty;
                if (lcr.Item.GetType() == typeof(IBK.lote_comprobantes_responseErrores_response))
                {
                    resultado = ((IBK.lote_comprobantes_responseErrores_response)lcr.Item).error[0].descripcion_error;
                }
                else if (!((IBK.lote_response)(lcr.Item)).estado.Equals("OK"))
                {
                    if (((IBK.lote_response)lcr.Item).errores_lote != null)
                    {
                        resultado += "Lote Nro.: " + ((IBK.lote_response)lcr.Item).id_lote + "  Estado: " + ((IBK.lote_response)lcr.Item).estado + "\\n";
                        foreach (IBK.error error in ((IBK.lote_response)lcr.Item).errores_lote)
                        {
                            resultado += error.codigo_error + " - " + error.descripcion_error + "\\n";
                        }
                        resultado += "\\n";
                    }
                    if (((IBK.lote_response)lcr.Item).comprobante_response != null)
                    {
                        foreach (IBK.comprobante_response cr in ((IBK.lote_response)lcr.Item).comprobante_response)
                        {
                            if (cr.errores_comprobante != null)
                            {
                                resultado += "Comprobante Nro.: " + cr.numero_comprobante + "\\n";
                                foreach (IBK.error error in cr.errores_comprobante)
                                {
                                    resultado += error.codigo_error + " - " + error.descripcion_error + "\\n";
                                }
                            }
                        }
                        resultado += "\\n";
                    }
                    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");
            }
        }