eSocialBX: Error 402 - "Invalid request"

Asked

Viewed 347 times

1

I’m trying to consume the web service Query to Event Identifiers, but I get this return:

<?xml version="1.0"?>
<eSocial xmlns="http://www.esocial.gov.br/schema/consulta/identificadores-eventos/retorno/v1_0_0">
  <retornoConsultaIdentificadoresEvts>
    <status>
      <cdResposta>402</cdResposta>
      <descResposta>Solicitação inválida. Redefina sua consulta</descResposta>
    </status>
  </retornoConsultaIdentificadoresEvts>
</eSocial>

I am sending the following XML:

<?xml version="1.0" encoding="utf-8"?>
<eSocial xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.esocial.gov.br/schema/consulta/identificadores-eventos/empregador/v1_0_0">
  <consultaIdentificadoresEvts>
    <ideEmpregador>
      <tpInsc>1</tpInsc>
      <nrInsc>00000000000000</nrInsc>
    </ideEmpregador>
    <consultaEvtsEmpregador>
      <tpEvt>S-1000</tpEvt>
      <perApur>2018</perApur>
    </consultaEvtsEmpregador>
  </consultaIdentificadoresEvts>
  <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/2001/04/xmldsig-more#rsa-sha256" />
      <Reference URI="">
        <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>7vfFTl1HHrHL5V/fTfL5Bmq3gUOarDwzGPhBCwrDKQ0=</DigestValue>
      </Reference>
    </SignedInfo>
    <SignatureValue>...</SignatureValue>
    <KeyInfo>
      <X509Data>
        <X509Certificate>...</X509Certificate>
      </X509Data>
    </KeyInfo>
  </Signature>
</eSocial>

This is the code that generated the XML above (I hid the CNPJ):

static void Main(string[] args)
{
   // Cria o objeto
   ServicoConsultarIdentificadoresEventosClient client = new ServicoConsultarIdentificadoresEventosClient();
   Modelos.ConsultaIdentificadoresEventos.eSocial esocial = new Modelos.ConsultaIdentificadoresEventos.eSocial();
   esocial.consultaIdentificadoresEvts = new eSocialConsultaIdentificadoresEvts();
   esocial.consultaIdentificadoresEvts.ideEmpregador = new TIdeEmpregador();
   esocial.consultaIdentificadoresEvts.ideEmpregador.tpInsc = 1;
   esocial.consultaIdentificadoresEvts.ideEmpregador.nrInsc = "00000000000000";
   esocial.consultaIdentificadoresEvts.consultaEvtsEmpregador = new TConsultaEventosEmpregador();
   esocial.consultaIdentificadoresEvts.consultaEvtsEmpregador.perApur = "2018";
   esocial.consultaIdentificadoresEvts.consultaEvtsEmpregador.tpEvt = "S-1000";

   // Carrega o certificado 
   X509Certificate2 certificado = new X509Certificate2();
   X509Store store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
   store.Open(OpenFlags.ReadOnly);
   certificado = store.Certificates[1];

   // Serializa o objeto
   var xml = Serialize(esocial);

   // Adiciona o certificado
   SignXmlDoc(xml, certificado);

   // Gera o arquivo XML no disco
   XmlSerializer xs = new XmlSerializer(typeof(XmlDocument));
   TextWriter txtWriter = new StreamWriter(@"C:\\temp\\Serialization.xml");
   xs.Serialize(txtWriter, xml);
   txtWriter.Close();

   // Define o certificado que será usado na chamada do WS
   client.ClientCredentials.ClientCertificate.Certificate = certificado;

   // Converte de document para element
   XDocument linqXml = XDocument.Parse(xml.OuterXml);

   // Chama o serviço enviando o XML      
   var retorno = client.ConsultarIdentificadoresEventosEmpregador(linqXml.Root);

   // Deserializa o objeto
   Modelos.RetornoIndeitificadoresEventos.eSocial deserialized = new Modelos.RetornoIndeitificadoresEventos.eSocial();
   StringReader reader = new StringReader(retorno.ToString());
   XmlSerializer xmlSerializer = new XmlSerializer(typeof(Modelos.RetornoIndeitificadoresEventos.eSocial));
   deserialized = (Modelos.RetornoIndeitificadoresEventos.eSocial)xmlSerializer.Deserialize(reader);
   client.Close();
}

I used xsd.exe and svcutil to generate the codes.
Someone has already obtained this error and knows how to solve or get more details?

  • It seems to me that you are not sending the request in the format or with valid values.

  • Did this employer already have something sent in 2018? Try removing the attributes xmlns:xsi and xmlns:xsd tag eSocial, before signing, to see if anything changes; see item 3 of that reply: https://answall.com/a/348662/86952

  • Yes, the employer sent this event last year. @Pedrogaspar I used your codes to serialize and remove the 2 attributes, but keeps returning me the same message.

1 answer

0


In addition to the tip I gave in the comments, for you to remove the attributes xmlns:xsi and xmlns:xsd tag eSocial, before signing (see item 3 of this reply: /a/348662/86952), I also noticed that in the tag nrInsc (in ideEmpregador) you are putting 14 zeros, but I believe that in this field you should put the employer root CNPJ, with 8 digits.

Anyway the problem is not that. I ran the query here and received the same error as you.

Since the beginning this eSocialBX documentation (Developer Manual v1.7) is very confusing and I never understood exactly where the S-1000 fit exactly, and where the Employer consultation method (which is what you’re using) fit in as well, because the manual says:

The method consultarIdentificadoresEventosEmpregador allows consultation of employer event identifiers that do not fall within the categories of periodic and non-periodical worker events or table events.

Now, the S-1000 would only remain if we looked at it as an 'Initial Event' rather than a table, although it has exactly the same structure as other table events. But then, because this method would have a field to inform the Event Type (tag tpEvt)?

And to make the confusion even worse, in the same manual, in the method section consultarIdentificadoresEventosTabela there is an example with the S-1000 event, which has always led me to believe that the S-1000 query should actually be done using the table method.

Good, but after all, what good is the method consultarIdentificadoresEventosEmpregador?? After a little thought and a few tests, I finally figured it out. Contrary to what the manual says, this method works to consult periodic events that do not refer to any worker, that is, those that refer to the employer. By logic, and by the tests I’ve done, it’s them:

  • S-1250 - Acquisition of Rural Production
  • S-1260 - Commercialization of Rural Production Individual
  • S-1270 - Hiring of Single Non-port Workers
  • S-1280 - Information Complementary to Periodic Events
  • S-1295 - Totalisation Request for Contingency Payment
  • S-1298 - Reopening of Periodic Events
  • S-1299 - Closing of Periodic Events
  • S-1300 - Trade Union Contribution Employers

I could not complete the test because of the limit of 10 daily consultations, but, so I understood the totalizing events of the employer S-5012 and S-5013 can also be consulted by this method of the employer, but, interestingly, the event S-5011 was not accepted by the method. I even sent a message to the eSocial team asking why this behavior (and complaining a little about the immense confusion of the manual explanations).

Completion:
To view the S-1000 event, use the method consultarIdentificadoresEventosTabela. An example of XML:

<?xml version="1.0" encoding="utf-8"?>
<eSocial xmlns="http://www.esocial.gov.br/schema/consulta/identificadores-eventos/tabela/v1_0_0">
   <consultaIdentificadoresEvts>
      <ideEmpregador>
         <tpInsc>1</tpInsc>
         <nrInsc>########</nrInsc>
      </ideEmpregador>
      <consultaEvtsTabela>
         <tpEvt>S-1000</tpEvt>
      </consultaEvtsTabela>
   </consultaIdentificadoresEvts>
</eSocial>

Complement:
When I was reviewing the answer I noticed a detail that I had never noticed in the documentation:

The method consultarIdentificadoresEventosEmpregador allows consultation of employer event identifiers that do not fall into the table event categories or periodic events and non-periodical of the worker.

I mean, it’s there, but it’s so subtle that I imagine that no one had ever attempted that detail.

Browser other questions tagged

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