How to consult Reinf-2099 - Inquiryreceipt event2099

Asked

Viewed 326 times

1

I am trying to query the Receiptent2099, however I do not know the correct form in the documentation speaks the URL and the method and also the parameters, I created an xml with the parameters and I am trying to send the request, but I always get this error:

Remote server returned an error: (400) Incorrect Request

What I am doing wrong or someone has an example of this C query#.

public string Consulta(X509Certificate2 cert)
{
    //string xmlRequisicaoSOAP = MontarXmlRequisicao();
    var xmlz = @"wwwroot\reinf\R_2099\consultaFechamento\ReinfLayout_R_2099_Consulta.xml";

    var xml = new XmlDocument();
    xml.Load(xmlz);

    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(@"https://preprodefdreinf.receita.fazenda.gov.br/wsreinf/ConsultasReinf.svc");
    request.Headers.Add("SOAPAction", "http://sped.fazenda.gov.br/ConsultasReinf/ConsultaReciboEvento2099");

    request.ContentType = "text/xml;charset=\"utf-8\"";
    request.Accept = "text/xml";
    request.Method = "POST";
    if (cert != null)
        request.ClientCertificates.Add(cert);
    if (this.TimeOutEmSegundos > 0)
        request.Timeout = this.TimeOutEmSegundos * 1000;

    this.UltimaRequisicao = xml.OuterXml;

    using (Stream stream = request.GetRequestStream())
    {
        using (StreamWriter stmw = new StreamWriter(stream))
        {
            stmw.Write(xml);
        }
    }

    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}{0}Detalhes subjacentes: {2}",
            System.Environment.NewLine, wex.Message, mensagemSubjacente);

        throw new InvalidOperationException(msg);
        //throw new ExcecaoComunicacaoREINF(msg, wex, xmlRequisicaoSOAP);
    }
    catch (Exception ex)
    {
        throw ex;
        // throw new ExcecaoComunicacaoREINF(ex.Message, ex, xmlRequisicaoSOAP);
    }
}

1 answer

1


You’re trying to use the following SOAPAction:

"http://sped.fazenda.gov.br/ConsultasReinf/ConsultaReciboEvento2099"

But, if you access the service’s WSDL on:

https://preprodefdreinf.receita.fazenda.gov.br/wsreinf/ConsultasReinf.svc?singleWsdl

You will see that the SOAPAction should be:

"http://sped.fazenda.gov.br/ConsultasReinf/ConsultaInformacoesConsolidadas"

The consultation of the event R-2099 (Closing of Periodic Events) is different from other EFD-Reinf events. You must enter the parameters tipoInscricaoContribuinte, numeroInscricaoContribuinte and numeroProtocoloFechamento, directly on the call to service, and will receive as return the event R-5011 (Background information and consolidated taxes by calculation period).

See an example query to the R-5011 (return of the R-2099) in this reply:

Reinf - Event error R-5011 - Stack Overflow

However, this answer uses the class it inherits System.ServiceModel.ClientBase, generated by adding a reference to the service, through Visual Studio, and if you want to do even direct SOAP communication "at hand" using HttpWebRequest (that gives more work and I do not know if it brings some extra benefit), instead of letting the . NET takes care of it for you, has this other answer (which is for eSocial, but the idea is the same):

Error 400 when sending request to Esocial (C#) - Stack Overflow

Remembering that the XML you are sending to the EFD-Reinf service may be the problem as well, since it should follow a specific schema, and should contain the SOAP tags, such as envelope and body. If you can not solve with the tips I passed, post your XML also in the question.

  • Thank you, I added here according to your example by wsdl, and managed to perform the query

Browser other questions tagged

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