Problem for sending SPED-REINF c#

Asked

Viewed 1,981 times

0

Dear friends,

I’m trying to send an xml to the SEFAZ for the SPED-REINF R-1000 code, I got help for the necessary methods here with the discussion list friends. But I am with the problem that I do not know how to solve, every file I try to send returns.

The remote server returned an error: (500) Internal Server Error. Underlying details are as follows: Processing failure. Please try again. Handle : 3033699826

the xml I’m sending and what follows:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sped="http://sped.fazenda.gov.br/">
<soap:Header />
<soap:Body>
    <REINF xmlns="http://www.reinf.esocial.gov.br/schemas/envioLoteEventos/v1_01_01">
        <loteEventos>
            <evento id="ID1">
                <Reinf xmlns="http://www.reinf.esocial.gov.br/schemas/evtInfoContribuinte/v1_02_00">
                    <evtInfoContri id="ID1000000032343842018011517062000001">
                        <ideEvento>
                            <tpAmb>1</tpAmb>
                            <procEmi>1</procEmi>
                            <verProc>1.0</verProc>
                        </ideEvento>
                        <ideContri>
                            <tpInsc>1</tpInsc>
                            <nrInsc>03234384</nrInsc>
                        </ideContri>
                        <infoContri>
                            <inclusao>
                                <idePeriodo>
                                    <iniValid>2018-01</iniValid>
                                </idePeriodo>
                                <infoCadastro>
                                    <classTrib>13</classTrib>
                                    <indEscrituracao>1</indEscrituracao>
                                    <indDesoneracao>0</indDesoneracao>
                                    <indAcordoIsenMulta>0</indAcordoIsenMulta>
                                    <indSitPJ>0</indSitPJ>
                                    <contato>
                                        <nmCtt>LUCAS VALFRIDO COSTA.</nmCtt>
                                        <cpfCtt>21513643991</cpfCtt>
                                        <foneFixo>(042)32195250</foneFixo>
                                        <email>[email protected]</email>
                                    </contato>
                                </infoCadastro>
                            </inclusao>
                        </infoContri>
                    </evtInfoContri>
                    <Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
                        <SignedInfo>
                            <CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" />
                            <SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" />
                            <Reference URI="#ID1000000032343842018011517062000001">
                                <Transforms>
                                    <Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" />
                                    <Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" />
                                </Transforms>
                                <DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256" />
                                <DigestValue>ffcLduYaxHryR1/P1I4/uvgD+8GFKSsN5zEn4aX/AaU=</DigestValue>
                            </Reference>
                        </SignedInfo>
                        <SignatureValue>NDwAI/SzB4E65rL3TecWRPNisXdaCXfPHnyHXO1VQ3Pp5MUoLq9XhrNQRdlFRVdhEsr7ZYtY7VrfCO/Ty++r5I9Nj4xYZFBSoKBLFSVkOW2RCOpeh3oV4MxY4Zb71wQScFPVsNbv1gHBkP5NhX9y8ZBknAmmtOFG79dMhCB1kHQXdX6a95gur3x2spviNOi/1RIvzK8s1MheilOXBYAKIlC0kfp7UQnkgjWoq/XK3LToHRuyMhhGQjcmG4S48B0ogAgScSClBzyP0s5eALFSNm+K6QTSJHIoB7lkNpilCZHW8zHkvi+BzY6EsoDAskf/wWsB1DwnxjFG8uoqrEteVQ==</SignatureValue>
                        <KeyInfo>
                            <X509Data>
                                <X509Certificate>MIIICjCCBfKgAwIBAgIQKmzokwPdnLVj3xB2tj4cszANBgkqhkiG9w0BAQsFADCBgDELMAkGA1UEBhMCQlIxEzARBgNVBAoTCklDUC1CcmFzaWwxNjA0BgNVBAsTLVNlY3JldGFyaWEgZGEgUmVjZWl0YSBGZWRlcmFsIGRvIEJyYXNpbCAtIFJGQjEkMCIGA1UEAxMbQUMgSW5zdGl0dXRvIEZlbmFjb24gUkZCIEczMB4XDTE3MTEwNzE2NDY0OFoXDTIwMTEwNjE2NDY0OFowgeMxCzAJBgNVBAYTAkJSMRMwEQYDVQQKDApJQ1AtQnJhc2lsM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TJnfVVcMBzwkoNpNwf7j2FUdmEzh/7fXkuKlDMcL3ie6mRZhtODKxYs+MJM7AVycj/G/u669SMa92qKN/adpjf+AieYISkvx1NWmK2WttV0JMFZQiJSqUN//FwOXKkQgR+hQI2fhaSiwltd8gqQgUIfItFdniM3CwdWtcz517o9DsB3E3+WTPUsrhR2tgpseZf0mro5tvrRuR2Zh6t8XxGGts/hOVLZw3hJNjI88KBIoRAHjKswQq/nb3uQIxXRa7HMHQqJYp/7C07VzTmMur8GedmqUorI8OVsRS92Ytl1og==</X509Certificate>
                            </X509Data>
                        </KeyInfo>
                    </Signature>
                </Reinf>
            </evento>
        </loteEventos>
    </REINF>
</soap:Body>

And the process for sending and the following:

    public string TransmitirDireto(string FilePath)
    {
        XmlDocument arquivoXML = new XmlDocument();
        arquivoXML.Load(FilePath.Trim());

        XmlTextWriter xmlWriter = new XmlTextWriter(FilePath, System.Text.Encoding.UTF8);
        xmlWriter.Formatting = Formatting.Indented;
        arquivoXML.Save(xmlWriter);
        //xmlWriter.Dispose();
        xmlWriter.Close();
        xmlWriter = null;

        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(this.URL);
        //request.Headers.Add("SOAPAction", string.Format("\"{0}{1}\"", XMLNS, METODO));
        request.Headers.Add("SOAPAction", @"https://preprodefdreinf.receita.fazenda.gov.br/RecepcaoLoteReinf.svc");
                                        //  https://preprodefdreinf.receita.fazenda.gov.br/RecepcaoLoteReinf.svc
        request.ContentType = "text/xml;charset=\"utf-8\"";
        request.Accept = "text/xml";
        request.Method = "POST";
        //  request.Proxy = proxy;

        if (this.Certificado != null)
            request.ClientCertificates.Add(this.Certificado);
        if (this.TimeOutEmSegundos > 0)
            request.Timeout = this.TimeOutEmSegundos * 1000;

        this.UltimaRequisicao = arquivoXML.InnerXml;
        try
        {

            using (Stream stream = request.GetRequestStream())
            {
                using (StreamWriter stmw = new StreamWriter(stream))
                {
                    stmw.Write(arquivoXML.InnerXml);
                }
            }
        }
        catch (Exception wex)
        {
            throw new Exception(wex.Message);
        }

        try
        {
            WebResponse webresponse = request.GetResponse();
            HttpWebResponse response = (HttpWebResponse)webresponse;
            //if(response.StatusCode == HttpStatusCode.OK)
            using (StreamReader responseReader = new StreamReader(response.GetResponseStream()))
            {
                string result = responseReader.ReadToEnd();
                return result;
            }
        }
        catch (WebException wex)
        {
            string mensagemSubjacente = ObterMensagemSubjacente(wex);
            string msg = string.Format("{1}\r\n{0}\r\n Detalhes subjacentes: \r\n{2}",
                System.Environment.NewLine, wex.Message, mensagemSubjacente);
            throw new ExcecaoComunicacaoREINF(msg, wex, arquivoXML.InnerXml);
            //  throw new Exception(wex.Message); 
        }
        catch (Exception ex)
        {
            throw new ExcecaoComunicacaoREINF(ex.Message, ex, arquivoXML.InnerXml);
        }
    }


    private static string ObterMensagemSubjacente(WebException wex)
    {
        //TODO rever
        if (wex.Response == null)
            return wex.Message;

        string mensagemSubjacente = string.Empty;
        using (Stream s = wex.Response.GetResponseStream())
        {
            StreamReader reader = new StreamReader(s);
            mensagemSubjacente = reader.ReadToEnd();

            try
            {
                XmlDocument xml = new XmlDocument();
                xml.LoadXml(mensagemSubjacente);
                XmlNodeList fault = xml.GetElementsByTagName("faultstring");
                if (fault != null && fault.Count > 0)
                {
                    mensagemSubjacente = fault[0].InnerText;
                }
            }
            catch (Exception ex)
            {
                return mensagemSubjacente;
            }
        }
        return mensagemSubjacente;
    }

If anyone can help me, I’d be very grateful.

1 answer

0


Are you reporting <tpAmb>1</tpAmb> in XML, but, the type of environment for the restricted production environment (testing environment) shall be 2. The type of environment 1 should only be used in the production environment (official), which is not yet released to anyone (will only be released from May/2018, but only for companies that had revenues higher than R $ 78 million in the year 2016).

Use then <tpAmb>2</tpAmb> in your XML, and try again.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.