coins5 / Atikux

Codigo Ejemplo de como hacer factura electronica
5 stars 7 forks source link

sendSummary #2

Open LibreTitan opened 7 years ago

LibreTitan commented 7 years ago

Hola de nuevo! Estoy tratando de enviar el sendSummary, pero me dice:

Error CS0029 No se puede convertir implícitamente el tipo 'string' en 'byte[]' Atikux C:\Users\LinEdx\Downloads\Atikux-master\Atikux-master\Atikux\classes\SunatServices.cs 41 Activa

Estoy haciendo algo mal?

coins5 commented 7 years ago

Hola LibreTitan,

En el catch donde está esa función hay 2 resultados. El que me envías es porque el servidor de Sunat ha dado una respuesta en String y lo puedes ver en [/CLIENT] mas abajo. Ese código de error lo puedes encontrar en el listado de errores:

Console.WriteLine("EXCEPTION :/");

            Console.WriteLine("#### [DEVELOPER] ####");
            Console.WriteLine(ex.ToString());
            Console.WriteLine("#### [/DEVELOPER] ####");

            Console.WriteLine("#### [CLIENT] ####");
            Console.WriteLine(ex.Code.Name);
            Console.WriteLine("#### [/CLIENT] ####");

Listado de Errores: https://www.google.com.pe/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&ved=0ahUKEwj8iOSp1M_MAhXHth4KHfDICkgQFgggMAA&url=http%3A%2F%2Fcontenido.app.sunat.gob.pe%2Finsc%2FComprobantesDePago%2BElectronicos%2FeFacturas%2Bd%2Bsistemas%2Bcontrib%2FAct%2B04.04.2014%2FANEXO%2B2%2Blistado%2Bde%2Berrores%2B-%2BMANUAL%2BDEL%2BPROGRAMADOR.DOCX&usg=AFQjCNE2WUTyIS5lRYcriGu-ElVZ6RsKqw&sig2=5BqgD14NRrz2xxNLyD3cVw

LibreTitan commented 7 years ago

Efectivamente, cuando uno envía el sendSummary solo devuelve un texto simple, como se podríalo implementar en este caso?

coins5 commented 7 years ago

Hola,

Linea 41: byte[] resultBytes = service.sendBill(NameOfFileZip, allbytes);

Se me ocurre que podría ser así:

var resultBytes = service.sendBill(NameOfFileZip, allbytes);

if(resultBytes is String) {
   // Tratar como string
} else {
   // convertir a byte[]
}
LibreTitan commented 7 years ago

He hecho esta chapuza (estoy aprendiendo c# a la mala): en .getStatus me aparece este error: No se puede convertir implícitamente el tipo 'Atikux.DocumentosElectronicoSunat.statusResponse' en 'byte[]'

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;

namespace Atikux.classes
{
    public class SunatServices
    {
        DocumentosElectronicoSunat.billServiceClient service;
        // string inputsPath = @"D:\nodejs\Atikux\inputs\";
        // string outputPath = @"D:\nodejs\Atikux\outputs\";

        string rootFolder = Environment.CurrentDirectory;
        string inputsPath = "";
        string outputPath = "";

        public SunatServices() {
            service = new DocumentosElectronicoSunat.billServiceClient();
            ServicePointManager.UseNagleAlgorithm = true;
            ServicePointManager.Expect100Continue = false;
            ServicePointManager.CheckCertificateRevocationList = true;

            inputsPath = rootFolder + @"\inputs\";
            outputPath = rootFolder + @"\outputs\";
        }

        public string sendDocument(string NameOfFileZip, string servicex) {
            string response = "";

            string folder = inputsPath + NameOfFileZip;
            byte[] allbytes = File.ReadAllBytes(folder);

            string FechaHora = DateTime.Now.ToString("yyyy-MM-dd hh.mm.ss");

            if (servicex =="sendBill")
            {
                try
                    {
                        service.Open();
                        byte[] resultBytes = service.sendBill(NameOfFileZip, allbytes);
                        service.Close();

                        string outputFile = outputPath + " " + FechaHora + " " + NameOfFileZip;

                        using (FileStream fs = new FileStream(outputFile, FileMode.Create))
                        {
                            fs.Write(resultBytes, 0, resultBytes.Length);
                            fs.Close();
                        }
                        response = "Zip received, unzip and readXML";
                        Console.WriteLine("OK: Zip received, unzip and readXML");

                }            // catch (Exception ex) {
                catch (System.ServiceModel.FaultException ex)
                {
                    Console.WriteLine("EXCEPTION :/");

                    Console.WriteLine("#### [DEVELOPER] ####");
                    Console.WriteLine(ex.ToString());
                    Console.WriteLine("#### [/DEVELOPER] ####");

                    Console.WriteLine("#### [CLIENT] ####");
                    Console.WriteLine(ex.Code.Name);
                    Console.WriteLine("#### [/CLIENT] ####");

                    response += ex.Code.Name;
                }
            } else if (servicex == "sendSummary")
            {
                try
                {
                    service.Open();
                    string resultBytes = service.sendSummary(NameOfFileZip, allbytes);
                    service.Close();

                    string outputFile = outputPath + " " + FechaHora + " " + NameOfFileZip + ".txt";

                    File.WriteAllText(outputFile, resultBytes.ToString());

                    response = "Zip received, unzip and readXML";
                    Console.WriteLine("OK: Zip received, unzip and readXML");

                }            // catch (Exception ex) {
                catch (System.ServiceModel.FaultException ex)
                {
                    Console.WriteLine("EXCEPTION :/");

                    Console.WriteLine("#### [DEVELOPER] ####");
                    Console.WriteLine(ex.ToString());
                    Console.WriteLine("#### [/DEVELOPER] ####");

                    Console.WriteLine("#### [CLIENT] ####");
                    Console.WriteLine(ex.Code.Name);
                    Console.WriteLine("#### [/CLIENT] ####");

                    response += ex.Code.Name;
                }
            }
            else if (servicex == "getStatus")
            {
                try
                {
                    service.Open();
                    byte[] resultBytes = service.getStatus(NameOfFileZip);
                    service.Close();

                    string outputFile = outputPath + " " + FechaHora + " " + NameOfFileZip;

                    using (FileStream fs = new FileStream(outputFile, FileMode.Create))
                    {
                        fs.Write(resultBytes, 0, resultBytes.Length);
                        fs.Close();
                    }
                    response = "Zip received, unzip and readXML";
                    Console.WriteLine("OK: Zip received, unzip and readXML");

                }            // catch (Exception ex) {
                catch (System.ServiceModel.FaultException ex)
                {
                    Console.WriteLine("EXCEPTION :/");

                    Console.WriteLine("#### [DEVELOPER] ####");
                    Console.WriteLine(ex.ToString());
                    Console.WriteLine("#### [/DEVELOPER] ####");

                    Console.WriteLine("#### [CLIENT] ####");
                    Console.WriteLine(ex.Code.Name);
                    Console.WriteLine("#### [/CLIENT] ####");

                    response += ex.Code.Name;
                }
            }
            return response;
        }
    }
}