I'm developing a messaging for reinf but I'm having trouble sending the first event. By sending a R1000 I'm getting the message:
MS0017
Invalid event signature. Digital signature of XML document is invalid
I am generating the event xml using the XmlSerializer class. First I download the xsd files from reinf, I pass them to xsd.exe to generate the classes in C #, I generate an event object, I populate the properties and then serialize as below:
XmlSerializer ArquivoSerializer = new XmlSerializer(typeof(T));
using (FileStream ArquivoStream = new FileStream(pObjArquivo.FullName, FileMode.CreateNew))
{
using (XmlWriter ArquivoWriter = XmlWriter.Create(ArquivoStream))
{
ArquivoSerializer.Serialize(ArquivoWriter, pSerializableObject);
}
return new FileInfo(ArquivoStream.Name);
}
So far so good. Then the manual asks us to send the event in the form of enveloped lots. Creating the batches xml in the same way did not work. Reinf rejects the generated file from your batch send xsd, so I've booted an alternative:
XNamespace ns = "http://www.reinf.esocial.gov.br/schemas/envioLoteEventos/v1_01_01";
XDocument eventoAssinado = XDocument.Load(pFileEventoAssinado.FullName);
XDocument doc = new XDocument(
new XElement(ns + "Reinf",
new XAttribute("xmlns", ns.NamespaceName),
new XAttribute(XNamespace.Xmlns + "xsd", "http://www.w3.org/2001/XMLSchema"),
new XAttribute(XNamespace.Xmlns + "xsi", "http://www.w3.org/2001/XMLSchema-instance"),
new XElement(ns + "loteEventos",
new XElement(ns + "evento",
new XAttribute("id", pFileEventoAssinado.Name.Replace(".xml", string.Empty)),
new XElement(eventoAssinado.Root)
))
));
This xml yes is processed by reinf, but returning the error of the beginning of the question. The question is: Is it that when I'm adding the Root of my event to the new xml this causes some change in the signed event itself, invalidating my signature? Can anyone recommend me a better practice than this one?
I use the same signing method in eSocial without any problems.