|
| 1 | +using OpenAC.Net.DFe.Core; |
| 2 | +using System; |
| 3 | +using System.Security.Cryptography.X509Certificates; |
| 4 | +using System.Text; |
| 5 | +using OpenAC.Net.Core.Extensions; |
| 6 | +using System.Xml.Linq; |
| 7 | +using System.Net; |
| 8 | +using System.Text.RegularExpressions; |
| 9 | +using System.Xml; |
| 10 | +using System.ServiceModel.Channels; |
| 11 | + |
| 12 | +namespace OpenAC.Net.NFSe.Providers.GISS |
| 13 | +{ |
| 14 | + internal class GISSServiceClient : NFSeSoapServiceClient, IServiceClient |
| 15 | + { |
| 16 | + #region Constructors |
| 17 | + |
| 18 | + public GISSServiceClient(ProviderGISS provider, TipoUrl tipoUrl, X509Certificate2 certificado) : base(provider, tipoUrl, certificado, SoapVersion.Soap11) |
| 19 | + { |
| 20 | + } |
| 21 | + |
| 22 | + public GISSServiceClient(ProviderGISS provider, TipoUrl tipoUrl) : base(provider, tipoUrl, SoapVersion.Soap11) |
| 23 | + { |
| 24 | + } |
| 25 | + |
| 26 | + #endregion Constructors |
| 27 | + |
| 28 | + #region Methods |
| 29 | + |
| 30 | + public string Enviar(string cabec, string msg) |
| 31 | + { |
| 32 | + var message = new StringBuilder(); |
| 33 | + message.Append("<nfse:RecepcionarLoteRpsRequest>"); |
| 34 | + message.Append("<nfseCabecMsg>"); |
| 35 | + message.AppendCData("<cabecalho versao=\"2.00\"><versaoDados>2.00</versaoDados></cabecalho>"); |
| 36 | + message.Append("</nfseCabecMsg>"); |
| 37 | + message.Append("<nfseDadosMsg>"); |
| 38 | + message.AppendCData(msg); |
| 39 | + message.Append("</nfseDadosMsg>"); |
| 40 | + |
| 41 | + message.Append("</nfse:RecepcionarLoteRpsRequest>"); |
| 42 | + |
| 43 | + return Execute("RecepcionarLoteRpsRequest", message.ToString(), "EnviarLoteRpsResposta"); |
| 44 | + } |
| 45 | + |
| 46 | + public string EnviarSincrono(string cabec, string msg) => throw new NotImplementedException("Função não implementada/suportada neste Provedor !"); |
| 47 | + |
| 48 | + public string ConsultarSituacao(string cabec, string msg) => throw new NotImplementedException("Função não implementada/suportada neste Provedor !"); |
| 49 | + |
| 50 | + public string ConsultarLoteRps(string cabec, string msg) |
| 51 | + { |
| 52 | + var message = new StringBuilder(); |
| 53 | + message.Append("<nfse:ConsultarLoteRps>"); |
| 54 | + message.Append("<ConsultarLoteRpsEnvio>"); |
| 55 | + message.AppendCData(msg); |
| 56 | + message.Append("</ConsultarLoteRpsEnvio>"); |
| 57 | + message.Append("</nfse:ConsultarLoteRps>"); |
| 58 | + |
| 59 | + return Execute("ConsultarLoteRps", message.ToString(), "ConsultarLoteRpsResposta"); |
| 60 | + } |
| 61 | + |
| 62 | + public string ConsultarSequencialRps(string cabec, string msg) => throw new NotImplementedException("Função não implementada/suportada neste Provedor !"); |
| 63 | + |
| 64 | + public string ConsultarNFSeRps(string cabec, string msg) |
| 65 | + { |
| 66 | + var message = new StringBuilder(); |
| 67 | + message.Append("<nfse:ConsultarNfseRpsEnvio>"); |
| 68 | + message.Append("<ConsultarNfseRpsEnvio>"); |
| 69 | + message.AppendCData(msg); |
| 70 | + message.Append("</ConsultarNfseRpsEnvio>"); |
| 71 | + message.Append("</nfse:consultarNfseRps>"); |
| 72 | + |
| 73 | + return Execute("ConsultarNfseRpsEnvio", message.ToString(), "ConsultarNfseRpsEnvioResponse"); |
| 74 | + } |
| 75 | + |
| 76 | + public string ConsultarNFSe(string cabec, string msg) => throw new NotImplementedException("Função não implementada/suportada neste Provedor !"); |
| 77 | + |
| 78 | + public string CancelarNFSe(string cabec, string msg) |
| 79 | + { |
| 80 | + var message = new StringBuilder(); |
| 81 | + message.Append("<nfse:cancelarNfse>"); |
| 82 | + message.Append("<CancelarNfseEnvio>"); |
| 83 | + message.AppendCData(msg); |
| 84 | + message.Append("</CancelarNfseEnvio>"); |
| 85 | + message.Append("</nfse:cancelarNfse>"); |
| 86 | + |
| 87 | + return Execute("cancelarNfse", message.ToString(), "CancelarNfseResposta"); |
| 88 | + } |
| 89 | + |
| 90 | + public string CancelarNFSeLote(string cabec, string msg) => throw new NotImplementedException("Função não implementada/suportada neste Provedor !"); |
| 91 | + |
| 92 | + public string SubstituirNFSe(string cabec, string msg) => throw new NotImplementedException("Função não implementada/suportada neste Provedor !"); |
| 93 | + |
| 94 | + private string Execute(string soapAction, string message, string responseTag) |
| 95 | + { |
| 96 | + return Execute(soapAction, message, "", responseTag, "xmlns:nfse=\"http://nfse.abrasf.org.br\""); |
| 97 | + } |
| 98 | + |
| 99 | + public bool ValidarUsernamePassword() |
| 100 | + { |
| 101 | + return !string.IsNullOrEmpty(Provider.Configuracoes.WebServices.Usuario) && !string.IsNullOrEmpty(Provider.Configuracoes.WebServices.Senha); |
| 102 | + } |
| 103 | + |
| 104 | + protected override string TratarRetorno(XElement xElement, string[] responseTag) |
| 105 | + { |
| 106 | + var reader = xElement.ElementAnyNs(responseTag[0]).CreateReader(); |
| 107 | + reader.MoveToContent(); |
| 108 | + var xml = reader.ReadInnerXml().Replace("ns2:", string.Empty); |
| 109 | + |
| 110 | + XmlDocument xmlDoc = new XmlDocument(); |
| 111 | + xmlDoc.LoadXml(xml); |
| 112 | + |
| 113 | + XmlDocument xmlMensagem = new XmlDocument(); |
| 114 | + xmlMensagem.LoadXml(xmlDoc.LastChild.InnerText); |
| 115 | + var mensagem = xmlMensagem.GetElementsByTagName("Mensagem"); |
| 116 | + if (mensagem.Count == 0) |
| 117 | + return xElement.ToString(); |
| 118 | + else |
| 119 | + return mensagem[0].InnerText; |
| 120 | + } |
| 121 | + |
| 122 | + #endregion Methods |
| 123 | + } |
| 124 | +} |
0 commit comments