XmlDSig Error: Did not find same-document Reference Id

If signing XML fails with the following message in the LastErrorText:

     Doing first SAX parse...
      passNumber: 1
        Did not find same-document Reference Id
        referenceId: id-1234567890

It means there was no XML element in the XML you were trying to sign that has an Id attribute with the given value.

For example, your source code might be trying to add a same-document reference like this:

    // -------- Reference 1 --------
    gen.AddSameDocRef("id-F9EFDBE6CD830436A2156958277490916","sha1","EXCL_C14N","oas soapenv v201 v202","");

    // -------- Reference 2 --------
    gen.AddSameDocRef("id-F9EFDBE6CD830436A2156958277490917","sha1","EXCL_C14N","oas v20 v201 v202","");

And the XML to be signed might look like this:

<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope ...>
        <v20:kontekstWywolania oas:Id="id-F9EFDBE6CD830436A2156958277490916">
    <soapenv:Body oas:Id="id-F9EFDBE6CD830436A2156958277490917">

Notice the Id attributes having the values that match the Id’s passed in the 1st argument to AddSameDocRef.
If the Id passed in AddSameDocRef is not found in the XML, then you’ll get the error “Did not find same-document Reference Id”

Tags :