From 119d04f64538e1484e08008d73fa0496837389b8 Mon Sep 17 00:00:00 2001 From: ROBERTO ALVES PEREIRA Date: Sun, 18 Feb 2024 14:56:12 -0300 Subject: [PATCH] =?UTF-8?q?fix:=20nova=20estrutura=20base=20de=20comunica?= =?UTF-8?q?=C3=A7=C3=A3o,=20mantendo=20o=20default?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DFe.Wsdl/Common/ConfiguracaoServicoWSDL.cs | 2 + DFe.Wsdl/Common/IRequestSefaz.cs | 18 ++++++++ DFe.Wsdl/Common/RequestSefazDefault.cs | 49 ++++++++++++++++++++++ 3 files changed, 69 insertions(+) create mode 100644 DFe.Wsdl/Common/IRequestSefaz.cs create mode 100644 DFe.Wsdl/Common/RequestSefazDefault.cs diff --git a/DFe.Wsdl/Common/ConfiguracaoServicoWSDL.cs b/DFe.Wsdl/Common/ConfiguracaoServicoWSDL.cs index aec09b777..32464bcfd 100644 --- a/DFe.Wsdl/Common/ConfiguracaoServicoWSDL.cs +++ b/DFe.Wsdl/Common/ConfiguracaoServicoWSDL.cs @@ -3,10 +3,12 @@ public static class ConfiguracaoServicoWSDL { public static bool ValidarCertificadoDoServidorNetCore { get; set; } + public static IRequestSefaz RequestSefaz { get; set; } static ConfiguracaoServicoWSDL() { ValidarCertificadoDoServidorNetCore = true; + RequestSefaz = new RequestSefazDefault(); } } } \ No newline at end of file diff --git a/DFe.Wsdl/Common/IRequestSefaz.cs b/DFe.Wsdl/Common/IRequestSefaz.cs new file mode 100644 index 000000000..909b8eb7d --- /dev/null +++ b/DFe.Wsdl/Common/IRequestSefaz.cs @@ -0,0 +1,18 @@ +using System.Security.Cryptography.X509Certificates; +using System.Threading.Tasks; +using System.Xml; +using CTe.CTeOSDocumento.Common; + +namespace DFe.Wsdl.Common +{ + public interface IRequestSefaz + { + XmlDocument SerealizeDocument(T soapEnvelope); + + Task SendRequestAsync(XmlDocument xmlEnvelop, X509Certificate2 certificadoDigital, string url, + int timeOut, TipoEvento? tipoEvento = null, string actionUrn = ""); + + string SendRequest(XmlDocument xmlEnvelop, X509Certificate2 certificadoDigital, string url, int timeOut, + TipoEvento? tipoEvento = null, string actionUrn = ""); + } +} \ No newline at end of file diff --git a/DFe.Wsdl/Common/RequestSefazDefault.cs b/DFe.Wsdl/Common/RequestSefazDefault.cs new file mode 100644 index 000000000..6773705c5 --- /dev/null +++ b/DFe.Wsdl/Common/RequestSefazDefault.cs @@ -0,0 +1,49 @@ +using System; +using System.IO; +using System.Net; +using System.Security.Cryptography.X509Certificates; +using System.Text; +using System.Threading.Tasks; +using System.Xml; +using System.Xml.Serialization; +using CTe.CTeOSDocumento.Common; +using CTe.CTeOSDocumento.Soap; +using DFe.Http.Ext; + +namespace DFe.Wsdl.Common +{ + public class RequestSefazDefault : IRequestSefaz + { + /// + /// Serializa a estrutura do envelope contida no objeto para um XmlDocument. + /// + /// + /// + /// + public XmlDocument SerealizeDocument(T soapEnvelope) + { + return ConfiguracaoServicoWSDL.RequestSefaz.SerealizeDocument(soapEnvelope); + } + + /// + /// Cria e envia a requisição HttpClient, retornando a resposta obtida do WebService. + /// + /// + /// + /// + /// + /// + /// + public async Task SendRequestAsync(XmlDocument xmlEnvelop, X509Certificate2 certificadoDigital, string url, int timeOut, TipoEvento? tipoEvento = null, string actionUrn = "") + { + return await ConfiguracaoServicoWSDL.RequestSefaz.SendRequestAsync(xmlEnvelop, certificadoDigital, url, timeOut, + tipoEvento, actionUrn); + } + + public string SendRequest(XmlDocument xmlEnvelop, X509Certificate2 certificadoDigital, string url, int timeOut, TipoEvento? tipoEvento = null, string actionUrn = "") + { + return ConfiguracaoServicoWSDL.RequestSefaz.SendRequest(xmlEnvelop, certificadoDigital, url, timeOut, + tipoEvento, actionUrn); + } + } +} \ No newline at end of file