Error Element Reference malformed in signedXml.ComputeSignature

0

Good morning, I'm newbie to nfe and I'm trying to send the science event of an access key to get the complete xml retrieve the code below the error when I try to call the signedXml.ComputeSignature method. the error only occurs when I define the refer.Uri="# ID210210" + tbchaveAcesso.Text.Trim () + "01"; if set with "" passes normally, the problem is that if I did not understand wrong you have to define it like this. Can anyone help me?

            nfeCabecMsg nfeCabecMsg = new nfeCabecMsg();
            nfeCabecMsg.versaoDados = "1.00";
            nfeCabecMsg.cUF = "91";

            StringBuilder sb = new StringBuilder();

            sb.Append("<envEvento xmlns=\"http://www.portalfiscal.inf.br/nfe\">");
            sb.Append("<versao>1.00</versao>");
            sb.Append("<idLote>000000000000001</idLote>");
            sb.Append("<evento>");
            sb.Append("<versao>\"1.00\"</versao>");
            sb.Append("<infEvento>");
            sb.Append("<id>ID210210" + tbchaveAcesso.Text.Trim() + "01</id>");
            sb.Append("<cOrgao>91</cOrgao>");
            sb.Append("<tpAmb>1</tpAmb>");
            sb.Append("<CNPJ>" + TbCNPJ.Text.Trim() + "</CNPJ>");
            sb.Append("<chNFe>" + tbDanfe.Text.Trim() + "</chNFe>");
            sb.Append("<dhEvento>" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:sszzz") + "</dhEvento>");
            sb.Append("<tpEvento>210210</tpEvento>");
            sb.Append("<nSeqEvento>1</nSeqEvento>");
            sb.Append("<verEvento>\"1.00\"</verEvento>");
            sb.Append("<detEvento>");
            sb.Append("<versao>\"1.00\"</versao>");
            sb.Append("<descEvento>Ciencia da Operacao</descEvento>");
            sb.Append("</detEvento>");
            sb.Append("</infEvento>");
            sb.Append("</evento>");
            sb.Append("</envEvento>");

            XmlDocument xmlEvento = new XmlDocument();
            xmlEvento.PreserveWhitespace = false;
            xmlEvento.LoadXml(sb.ToString());

            var elementEvento = xmlEvento.GetElementsByTagName("evento")[0];


            var signedXml = new SignedXml(xmlEvento);
            signedXml.SigningKey = certificado.PrivateKey;
            signedXml.SignedInfo.CanonicalizationMethod = SignedXml.XmlDsigExcC14NTransformUrl;
            var refer = new Reference();
           // refer.Uri = string.Empty;
            refer.Uri = "#ID210210" + tbchaveAcesso.Text.Trim() + "01";
            refer.AddTransform(new XmlDsigEnvelopedSignatureTransform());
            refer.AddTransform(new XmlDsigC14NTransform());
            signedXml.AddReference(refer);
            var ki = new KeyInfo();
            ki.AddClause(new KeyInfoX509Data(certificado));
            signedXml.KeyInfo = ki;
            signedXml.ComputeSignature();

TosolvethisproblemIchangedthecreationofxmlto

StringBuildersb=newStringBuilder();

sb.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
            sb.Append("<envEvento xmlns=\"http://www.portalfiscal.inf.br/nfe\" versao =\"1.00\">");
            sb.Append("<idLote>2</idLote>");
            sb.Append("<evento xmlns=\"http://www.portalfiscal.inf.br/nfe\" versao =\"1.00\">");
            sb.Append("<infEvento Id=\"ID210210" + tbDanfe.Text.Trim() + "01\">");
            sb.Append("<cOrgao>91</cOrgao>");
            sb.Append("<tpAmb>1</tpAmb>");
            sb.Append("<CNPJ>" + TbCNPJ.Text.Trim() + "</CNPJ>");
            sb.Append("<chNFe>" + tbDanfe.Text.Trim() + "</chNFe>");
            sb.Append("<dhEvento>" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:sszzz") + "</dhEvento>");
            sb.Append("<tpEvento>210210</tpEvento>");
            sb.Append("<nSeqEvento>1</nSeqEvento>");
            sb.Append("<verEvento>1.00</verEvento>");
            sb.Append("<detEvento versao = \"1.00\">");
            sb.Append("<descEvento>Ciencia da Operacao</descEvento>");
            sb.Append("</detEvento>");
            sb.Append("</infEvento>");
            sb.Append("</evento>");
            sb.Append("</envEvento>");

However, although the RS validator is validano successfully, I have rejection msg 225

    
asked by anonymous 27.10.2018 / 14:26

0 answers