Skip to content

Commit

Permalink
fix: criar uma instancia para cada instancia do SoapUtils , nunca uti…
Browse files Browse the repository at this point in the history
…lizar a mesma
  • Loading branch information
robertorp committed Mar 1, 2024
1 parent 23f1c3a commit addf0cd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
18 changes: 15 additions & 3 deletions DFe.Wsdl/Common/ConfiguracaoServicoWSDL.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
namespace DFe.Wsdl.Common
using System;

namespace DFe.Wsdl.Common
{
public static class ConfiguracaoServicoWSDL
{
public static bool ValidarCertificadoDoServidorNetCore { get; set; }
public static IRequestSefaz RequestSefaz { get; set; }
private static Func<IRequestSefaz> _requestSefazFactory;

public static void SetRequestSefazFactory(Func<IRequestSefaz> factory)
{
_requestSefazFactory = factory;
}

public static IRequestSefaz GetRequestSefaz()
{
return _requestSefazFactory();
}

static ConfiguracaoServicoWSDL()
{
ValidarCertificadoDoServidorNetCore = true;
RequestSefaz = new RequestSefazDefault();
SetRequestSefazFactory(() => new RequestSefazDefault());
}
}
}
13 changes: 10 additions & 3 deletions DFe.Wsdl/Common/SoapUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ namespace CTe.CTeOSDocumento.Soap
/// </summary>
public class SoapUtils
{
private IRequestSefaz _requestSefaz;

public SoapUtils()
{
_requestSefaz = ConfiguracaoServicoWSDL.GetRequestSefaz();
}

/// <summary>
/// Serializa a estrutura do envelope contida no objeto para um XmlDocument.
/// </summary>
Expand All @@ -26,7 +33,7 @@ public class SoapUtils
/// <returns></returns>
public XmlDocument SerealizeDocument<T>(T soapEnvelope)
{
return ConfiguracaoServicoWSDL.RequestSefaz.SerealizeDocument(soapEnvelope);
return _requestSefaz.SerealizeDocument(soapEnvelope);
}

/// <summary>
Expand All @@ -40,12 +47,12 @@ public XmlDocument SerealizeDocument<T>(T soapEnvelope)
/// <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);
return await _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);
return _requestSefaz.SendRequest(xmlEnvelop, certificadoDigital, url, timeOut, tipoEvento, actionUrn);
}
}

Expand Down

0 comments on commit addf0cd

Please sign in to comment.