Example #1
0
        public TRetEnviNFe EnviaLote2(HiperNFe Notas, int NumLote)
        {
            XmlNode strRetorno = null;
            dynamic xmldoc = new XmlDocument();

            ListaUrl listaURL = default(ListaUrl);
            listaURL = WsUrls.BuscaURL(Notas.Configuracao.CodUF, Notas.Configuracao.Ambiente);

            string nomeArquivoLote = _PastaLog + NumLote.ToString() + "-env-lot.xml";
            string nomeArquivoRetLote = _PastaLog + NumLote.ToString() + "-rec.xml";

            try
            {
                TEnviNFe LoteNFe = new TEnviNFe();
                LoteNFe.idLote = NumLote.ToString();
                LoteNFe.versao = Notas.Configuracao.Versao;
                // ERROR: Not supported in C#: ReDimStatement

                int indice = 0;
                LoteNFe.NFe = new TNFe[Notas.NotasFiscais.Count];
                foreach (TNfeProc nota in Notas.NotasFiscais)
                {
                    LoteNFe.NFe[indice] = nota.NFe;
                    indice += 1;
                }
                LoteNFe.GeraLoteNFe(nomeArquivoLote);
                xmldoc.Load(nomeArquivoLote);
                //Carrega o arquivo XML 

                Recepcao2.NfeRecepcao2 wsMsg = default(Recepcao2.NfeRecepcao2);
                Recepcao2.nfeCabecMsg cab = new Recepcao2.nfeCabecMsg();

                //UF E VERSÃO DO CABEÇALHO
                cab.cUF = PegarCodigoUF(Notas.Configuracao.CodUF);
                cab.versaoDados = LoteNFe.versao;

                //CABEÇALHO USADA PARA ENVIO DE LOTE
                wsMsg = new Recepcao2.NfeRecepcao2(listaURL.UrlNfeRecepcao);
                wsMsg.nfeCabecMsgValue = cab;

                wsMsg.Timeout = 100000;
                wsMsg.ClientCertificates.Add(Notas.Certificado);
                wsMsg.SoapVersion = SoapProtocolVersion.Soap12;

                xmldoc.Save(nomeArquivoLote);
                //RETORNO DA SEFAZ
                strRetorno = wsMsg.nfeRecepcaoLote2(xmldoc);
                TRetEnviNFe retornoEnvio = new TRetEnviNFe();
                XmlDocument retornoXML = new XmlDocument();
                retornoXML.LoadXml(strRetorno.OuterXml);
                retornoXML.Save(nomeArquivoRetLote);
                retornoEnvio = TRetEnviNFe.LoadFromFile(nomeArquivoRetLote);

                return retornoEnvio;
            }
            catch (Exception)
            {
                throw new ACBr.Net.NFe.Exceptions.EnviaLote2Exception("Falha ao enviar o lote de NFe.");
            }
        }
 /// <summary>
 /// Deserializes workflow markup into an TEnviNFe object
 /// </summary>
 /// <param name="xml">string workflow markup to deserialize</param>
 /// <param name="obj">Output TEnviNFe object</param>
 /// <param name="exception">output Exception value if deserialize failed</param>
 /// <returns>true if this XmlSerializer can deserialize the object; otherwise, false</returns>
 public static bool Deserialize(string xml, out TEnviNFe obj, out System.Exception exception)
 {
     exception = null;
     obj       = default(TEnviNFe);
     try
     {
         obj = Deserialize(xml);
         return(true);
     }
     catch (System.Exception ex)
     {
         exception = ex;
         return(false);
     }
 }
 public static bool LoadFromFile(string fileName, out TEnviNFe obj)
 {
     System.Exception exception = null;
     return LoadFromFile(fileName, out obj, out exception);
 }
 /// <summary>
 /// Deserializes xml markup from file into an TEnviNFe object
 /// </summary>
 /// <param name="fileName">string xml file to load and deserialize</param>
 /// <param name="obj">Output TEnviNFe object</param>
 /// <param name="exception">output Exception value if deserialize failed</param>
 /// <returns>true if this XmlSerializer can deserialize the object; otherwise, false</returns>
 public static bool LoadFromFile(string fileName, System.Text.Encoding encoding, out TEnviNFe obj, out System.Exception exception)
 {
     exception = null;
     obj = default(TEnviNFe);
     try
     {
         obj = LoadFromFile(fileName, encoding);
         return true;
     }
     catch (System.Exception ex)
     {
         exception = ex;
         return false;
     }
 }
 public static bool Deserialize(string xml, out TEnviNFe obj)
 {
     System.Exception exception = null;
     return Deserialize(xml, out obj, out exception);
 }
 /// <summary>
 /// Deserializes workflow markup into an TEnviNFe object
 /// </summary>
 /// <param name="xml">string workflow markup to deserialize</param>
 /// <param name="obj">Output TEnviNFe object</param>
 /// <param name="exception">output Exception value if deserialize failed</param>
 /// <returns>true if this XmlSerializer can deserialize the object; otherwise, false</returns>
 public static bool Deserialize(string xml, out TEnviNFe obj, out System.Exception exception)
 {
     exception = null;
     obj = default(TEnviNFe);
     try
     {
         obj = Deserialize(xml);
         return true;
     }
     catch (System.Exception ex)
     {
         exception = ex;
         return false;
     }
 }
 public static bool LoadFromFile(string fileName, out TEnviNFe obj)
 {
     System.Exception exception = null;
     return(LoadFromFile(fileName, out obj, out exception));
 }
 public static bool LoadFromFile(string fileName, out TEnviNFe obj, out System.Exception exception)
 {
     return(LoadFromFile(fileName, Encoding.UTF8, out obj, out exception));
 }
 /// <summary>
 /// Deserializes xml markup from file into an TEnviNFe object
 /// </summary>
 /// <param name="fileName">string xml file to load and deserialize</param>
 /// <param name="obj">Output TEnviNFe object</param>
 /// <param name="exception">output Exception value if deserialize failed</param>
 /// <returns>true if this XmlSerializer can deserialize the object; otherwise, false</returns>
 public static bool LoadFromFile(string fileName, System.Text.Encoding encoding, out TEnviNFe obj, out System.Exception exception)
 {
     exception = null;
     obj       = default(TEnviNFe);
     try
     {
         obj = LoadFromFile(fileName, encoding);
         return(true);
     }
     catch (System.Exception ex)
     {
         exception = ex;
         return(false);
     }
 }
 public static bool Deserialize(string xml, out TEnviNFe obj)
 {
     System.Exception exception = null;
     return(Deserialize(xml, out obj, out exception));
 }
 public static bool LoadFromFile(string fileName, out TEnviNFe obj, out System.Exception exception)
 {
     return LoadFromFile(fileName, Encoding.UTF8, out obj, out exception);
 }