Skip to content

Commit

Permalink
Merge pull request #1495 from ZeusAutomacao/ra/feat-nova-estrutura-base
Browse files Browse the repository at this point in the history
fix: nova estrutura base de comunicação, mantendo o default
  • Loading branch information
robertorp authored Feb 18, 2024
2 parents ba34fa3 + 119d04f commit 5f03b43
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
2 changes: 2 additions & 0 deletions DFe.Wsdl/Common/ConfiguracaoServicoWSDL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
18 changes: 18 additions & 0 deletions DFe.Wsdl/Common/IRequestSefaz.cs
Original file line number Diff line number Diff line change
@@ -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>(T soapEnvelope);

Task<string> 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 = "");
}
}
49 changes: 49 additions & 0 deletions DFe.Wsdl/Common/RequestSefazDefault.cs
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// Serializa a estrutura do envelope contida no objeto para um XmlDocument.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="soapEnvelope"></param>
/// <returns></returns>
public XmlDocument SerealizeDocument<T>(T soapEnvelope)
{
return ConfiguracaoServicoWSDL.RequestSefaz.SerealizeDocument(soapEnvelope);
}

/// <summary>
/// Cria e envia a requisição HttpClient, retornando a resposta obtida do WebService.
/// </summary>
/// <param name="xmlEnvelop"></param>
/// <param name="certificadoDigital"></param>
/// <param name="url"></param>
/// <param name="timeOut"></param>
/// <param name="tipoEvento"></param>
/// <returns></returns>
public async Task<string> 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);
}
}
}

0 comments on commit 5f03b43

Please sign in to comment.