C# - EFD Reinf v1_04_00 - return - nrProtEntr - return treatment

Asked

Viewed 233 times

0

After successfully sending the R1000 event, through the questions:

I got the return on the variable and I need to treat it:

var retornoEnvioXElement = wsClient.ReceberLoteEventos(doc.Root);

? return

{<Reinf xmlns="http://www.reinf.esocial.gov.br/schemas/retornoLoteEventos/v1_04_00">
  <retornoLoteEventos id="IDF4EBD1BA1DDE6A0B288DD85C8DF1E535">
    <ideTransmissor>
      <IdTransmissor>01628604000140</IdTransmissor>
    </ideTransmissor>
    <status>
      <cdStatus>0</cdStatus>
      <descRetorno>SUCESSO</descRetorno>
    </status>
    <retornoEventos>
      <evento id="ID1016286040000002018121309305100001">
        <Reinf xmlns="http://www.reinf.esocial.gov.br/schemas/evtTotal/v1_04_00">
          <evtTotal id="ID-1066770329">
            <ideEvento>
              <perApur />
            </ideEvento>
            <ideContri>
              <tpInsc>1</tpInsc>
              <nrInsc>01628604</nrInsc>
            </ideContri>
            <ideRecRetorno>
              <ideStatus>
                <cdRetorno>0</cdRetorno>
                <descRetorno>SUCESSO</descRetorno>
              </ideStatus>
            </ideRecRetorno>
            <infoRecEv>
              <dhProcess>2018-12-13T09:31:39.1306938-02:00</dhProcess>
              <tpEv>1000</tpEv>
              <idEv>ID1016286040000002018121309305100001</idEv>
              <hash>dw94b8lBK83zUyVwc6p8obI8F1fc/Ag0NkU2QHWi/Og=</hash>
            </infoRecEv>
            <infoTotal>
              <nrRecArqBase>14009-04-1000-1812-14009</nrRecArqBase>
              <ideEstab>
                <tpInsc>0</tpInsc>
              </ideEstab>
            </infoTotal>
          </evtTotal>
          <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="#ID-1066770329">
                <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>sfY6hV4oPUQhpjcLMZa61Odj8xEQOvAdyLXJOYfvS4g=</DigestValue>
              </Reference>
            </SignedInfo>
            <SignatureValue>[...]</SignatureValue>
            <KeyInfo>
              <X509Data>
                <X509Certificate>[...]</X509Certificate>
              </X509Data>
            </KeyInfo>
          </Signature>
        </Reinf>
      </evento>
    </retornoEventos>
  </retornoLoteEventos>
</Reinf>}

I ask you: Which fields should I store for later queries of what has already been sent?

I was expecting the nrProtEntr "Event delivery protocol number", but it did not come in this return. That’s right?

Only the <hash>dw94b8lBK83zUyVwc6p8obI8F1fc/Ag0NkU2QHWi/Og=</hash> is sufficient for in the future to recover Delivery Receipts?

1 answer

1


The field nrProtEntr is returned only when sending the R-2099 closing event (see here how to consult the return of this event), in the case of other events the field you must pick up is the nrRecArqBase.

To treat the return, this object XElement can be "de-serialized" to a class generated by the XSD.exe tool, through the Xsds of EFD-Reinf Communication Package v1.04.00, using these functions:

// Pode ser usado para XDocument, XElement, XContainer, XNode.
public T DeserializeFromXNode<T>(XNode xNode)
{
   using (var reader = xNode.CreateReader())
   {
      var xs = new XmlSerializer(typeof(T));
      return (T)xs.Deserialize(reader);
   }
}

// Pode ser usado para XmlDocument, XmlElement, XmlNode e outros.
public T DeserializeFromXmlNode<T>(XmlNode xmlNode)
{
   using (var reader = new XmlNodeReader(xmlNode))
   {
      var xs = new XmlSerializer(typeof(T));
      return (T)xs.Deserialize(reader);
   }
}

That can be used that way:

var retornoEnvio = DeserializeFromXNode<RetornoLoteEventos.Reinf>(retornoEnvioXElement);
var eventos = retornoEnvio?.retornoLoteEventos.retornoEventos?.evento;

foreach (var retornoEvtXml in eventos)
{
   var retornoEvt = DeserializeFromXmlNode<RetornoTotalizadorEvento.Reinf>(retornoEvtXml.Any);
   if (retornoEvt.evtTotal.ideRecRetorno.ideStatus.cdRetorno != 0)
      continue;
   var nrRecibo = retornoEvt.evtTotal.infoTotal?.nrRecArqBase;
   var hash = retornoEvt.evtTotal.infoRecEv.hash;
}

About the need or not to guard the field hash, the EFD-Reinf v1.4 Developer Guidance Manual says the following on page 32:

In order to be able to recover the number of the receipt the event must be sent back to national environment following the following premises:

a) Event must be the same as previously submitted;
b) Must have the same HASH;
c) The same ID as the one sent on the first attempt should be maintained;

So it might be a good idea to store that field, yes.

  • Doubt: on the line: var returns I created this way... Is returning me the following error: on the line Return(T)Xs.Deserialize(Reader) from Function Deserializefromxnode<T> Returns the following error: System.Invalidoperationexception: 'There is an error in XML Document (0, 0). ' Internal Exception: Invalidoperationexception: <Reinf xmlns='http://www.reinf.esocial.gov.br/schemas/returns.

  • ? (T)Xs. Deserialize(reader);&#xA;'(T)xs.Deserialize(reader)' gerou uma exceção do tipo 'System.InvalidOperationException'&#xA; Data: {System.Collections.ListDictionaryInternal}&#xA; HResult: -2146233079&#xA; HelpLink: null&#xA; InnerException: {"<Reinf xmlns='http://www.reinf.esocial.gov.br/schemas/returns } Message: "There is an error in XML Document (0, 0)." &#xA; Source: "System.Xml"&#xA; StackTrace: " at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)\r\n at ...

  • That, in this case RetornoLoteEventos is the namespace. What is the content of the return variable retornoEnvioXElement when you hover over, on debug? There’s something or it’s empty?

  • 1

    In class Reinf which was generated by the 'XSD.exe' tool, for the schema retornoLoteEventos, the value of the parameter Namespace, of the attribute XmlTypeAttribute, is how? Is the same value that is there in the error, and in the return XML? By schema official, the value should be "http://www.reinf.esocial.gov.br/schemas/retornoLoteEventos/v1_04_00".

  • I found out: this line you mentioned was commented on due to error... [System.xml.Serialization.Xmltypeattribute(Anonymoustype=true, Namespace="http://www.reinf.esocial.gov.br/schemas/evtTotal/v1_04_00")] Thank you

  • the instance of var events = return Send? .return I put, and on the line : var returns CS1503 Argument 1: Unable to convert from "Return Events.Tarquivoreinf" to "System.xml.Xmlnode"

  • 1

    @Vagnercosta, yes, was missing one ; at the end of that line, and there was also an error in the line of performance, I’m sorry. I edited the answer, see if it now works.

  • @Vagnercosta, did you test it? Now it worked?

  • Yes, it worked! Thank you very much! I had already flagged your comment as "useful"!

Show 4 more comments

Browser other questions tagged

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