diff --git a/Infrastructure/SoapFaultException.cs b/Infrastructure/SoapFaultException.cs index 51b0997..8a1b91c 100644 --- a/Infrastructure/SoapFaultException.cs +++ b/Infrastructure/SoapFaultException.cs @@ -3,10 +3,26 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Infra; namespace Infra { - internal class SoapFaultException + public class SoapFaultException : Exception { + public string FaultCode { get; } + public string FaultString { get; } + public string ErrorCode { get; } + public string ErrorMessage { get; } + + public SoapFaultException(string faultCode, string faultString, string errorCode, string errorMessage) + : base($"{faultString} (Code: {errorCode})") + { + FaultCode = faultCode; + FaultString = faultString; + ErrorCode = errorCode; + ErrorMessage = errorMessage; + } } } + + diff --git a/Infrastructure/SoapHelper.cs b/Infrastructure/SoapHelper.cs index 3e03f17..f998e46 100644 --- a/Infrastructure/SoapHelper.cs +++ b/Infrastructure/SoapHelper.cs @@ -3,10 +3,30 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Xml.Linq; namespace Infra { - internal class SoapHelper + public static class SoapHelper { + public static void VerificarRespostaSOAP(string responseXml) + { + var doc = XDocument.Parse(responseXml); + XNamespace env = "http://schemas.xmlsoap.org/soap/envelope/"; + XNamespace tns = "http://xmlns.energia.org.br/FM/v2"; + + var fault = doc.Descendants(env + "Fault").FirstOrDefault(); + if (fault != null) + { + string faultCode = fault.Element("faultcode")?.Value ?? ""; + string faultString = fault.Element("faultstring")?.Value ?? ""; + + var detail = fault.Element("detail")?.Descendants().First(); + string errorCode = detail?.Element(tns + "errorCode")?.Value ?? ""; + string message = detail?.Element(tns + "message")?.Value ?? ""; + + throw new SoapFaultException(faultCode, faultString, errorCode, message); + } + } } } diff --git a/Program.cs b/Program.cs index 0b9da98..bacc53f 100644 --- a/Program.cs +++ b/Program.cs @@ -383,42 +383,6 @@ internal class Plat_integ } return; } - public class SoapFaultException : Exception - { - public string FaultCode { get; } - public string FaultString { get; } - public string ErrorCode { get; } - public string ErrorMessage { get; } - - public SoapFaultException(string faultCode, string faultString, string errorCode, string errorMessage) - : base($"{faultString} (Code: {errorCode})") - { - FaultCode = faultCode; - FaultString = faultString; - ErrorCode = errorCode; - ErrorMessage = errorMessage; - } - } - - public static void VerificarRespostaSOAP(string responseXml) - { - var doc = XDocument.Parse(responseXml); - XNamespace env = "http://schemas.xmlsoap.org/soap/envelope/"; - XNamespace tns = "http://xmlns.energia.org.br/FM/v2"; - - var fault = doc.Descendants(env + "Fault").FirstOrDefault(); - if (fault != null) - { - string faultCode = fault.Element("faultcode")?.Value ?? ""; - string faultString = fault.Element("faultstring")?.Value ?? ""; - - var detail = fault.Element("detail")?.Descendants().First(); - string errorCode = detail?.Element(tns + "errorCode")?.Value ?? ""; - string message = detail?.Element(tns + "message")?.Value ?? ""; - - throw new SoapFaultException(faultCode, faultString, errorCode, message); - } - } } public class perfil