Cliente C# para Enviar Boleta Electrónica usando AppDTE API
Este ejemplo muestra cómo consumir el endpoint REST de AppDTE desde un cliente C#. El servicio permite enviar un DTE tipo 39 (boleta electrónica).
🔧 Requisitos
.NET Core (Quizás pueda funcionar con .NET Framework)
Referencia Newtonsfot
using System;using System.Net.Http;using System.Text;using System.Threading.Tasks;using Newtonsoft.Json;
class Program{ static async Task Main(string[] args) { var data = new { emisor = new { rutemisor = "76040308-3", rznsoc = "EGGA INFORMATICA E.I.R.L", giroemis = "VENTA AL POR MENOR EN COMERCIOS ESPECIAL", acteco = "107100", dirorigen = "RAFAEL CASANOVA 297", cmnaorigen = "SANTA CRUZ", ciudadorigen = "SANTA CRUZ", fchresol = "2016-04-25", nroresol = "0", cdgsiisucur = "1" }, receptor = new { rutrecep = "9375855-2", rznsocrecep = "LUZMIRA CESPEDES NAVARRO", girorecep = "PROVISIONES", dirrecep = "ADRIANO DIAZ 560", cmnarecep = "Santa Cruz", ciudadrecep = "Santa Cruz", rutcaratula = "60803000-K" }, iddoc = new { tipodte = "39", folio = "1", fchemis = "2025-03-13", indservicio = "3", indmntneto = "2" }, totales = new { mntneto = "15126", iva = "2874", tasaiva = "19", mnttotal = "18000" }, detalle = new [] { new { nrolindet = "1", cdgitem = new [] { new { tpocodigo = "INT", vlrcodigo = "01001" } }, unmditem = "UN", nmbitem = "PAN CORRIENTE", qtyitem = "10", prcitem = "1800", descuentopct = "0", descuentomonto = "0", indexe = "0", montoitem = "18000" } }, usuario = new { login = "eguenul", rut = "13968481-8", password = "amulen1956" } };
using (HttpClient client = new HttpClient()) { var jsonContent = new StringContent(JsonConvert.SerializeObject(data), Encoding.UTF8, "application/json");
HttpResponseMessage response = await client.PostAsync("http://localhost:8080/AppDTEWS/api/sendDTE", jsonContent);
if (response.IsSuccessStatusCode) { Console.WriteLine("Solicitud exitosa"); string responseBody = await response.Content.ReadAsStringAsync(); Console.WriteLine(responseBody); } else { Console.WriteLine($"Error: {response.StatusCode}"); string errorContent = await response.Content.ReadAsStringAsync(); Console.WriteLine(errorContent); } } }}
Comentarios
Publicar un comentario