Open LibreTitan opened 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] ####");
Efectivamente, cuando uno envía el sendSummary solo devuelve un texto simple, como se podríalo implementar en este caso?
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[]
}
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;
}
}
}
Hola de nuevo! Estoy tratando de enviar el sendSummary, pero me dice:
Estoy haciendo algo mal?