C# 如何在C语言中为签名元素添加前缀#

C# 如何在C语言中为签名元素添加前缀#,c#,ws-security,x509certificate2,xml-signature,signedxml,C#,Ws Security,X509certificate2,Xml Signature,Signedxml,我们正在使用SignedXml类对xml元素进行签名。需求是在Ws-Security中添加签名节点以与服务通信 我们可以在这些元素上签名并进行验证。在本例中,xml示例代码如下所示 X509Certificate2 certificate = new X509Certificate2(CertPath, CertPassword); // Create a new XML document. XmlDocument doc = new XmlDocument()

我们正在使用SignedXml类对xml元素进行签名。需求是在Ws-Security中添加签名节点以与服务通信

我们可以在这些元素上签名并进行验证。在本例中,xml示例代码如下所示

        X509Certificate2 certificate = new X509Certificate2(CertPath, CertPassword);

    // Create a new XML document.
    XmlDocument doc = new XmlDocument();

    // Format the document to ignore white spaces.
    doc.PreserveWhitespace = false;

    // Load the passed XML file using it's name.
    doc.Load(new XmlTextReader(FileName));

    SignedXml signedXml = new SignedXml(doc);
    signedXml.SigningKey = certificate.PrivateKey;


    // Create a reference to be signed.
    Reference reference = new Reference();

    reference.Uri = "#" + elementID;

    // Add an enveloped transformation to the reference.
     XmlDsigEnvelopedSignatureTransform envTransform = new XmlDsigEnvelopedSignatureTransform();
    reference.AddTransform(envTransform);

    // Add the reference to the SignedXml object.
    signedXml.AddReference(reference);



    // Create a new KeyInfo object.
    KeyInfo keyInfo = new KeyInfo();

    // Load the certificate into a KeyInfoX509Data object
    // and add it to the KeyInfo object.
    keyInfo.AddClause(new KeyInfoX509Data(certificate));

    // Add the KeyInfo object to the SignedXml object.
    signedXml.KeyInfo = keyInfo;

    // Compute the signature.
    signedXml.ComputeSignature();


    // Get the XML representation of the signature and save
    // it to an XmlElement object.
    XmlElement xmlDigitalSignature = signedXml.GetXml();
通过使用此签名元素生成为。但我们想把它生成为

尝试显式设置前缀,但之后签名未被验证


您能指导我们如何做到这一点吗?

因为这是一个足够普遍的问题


对于我正在处理的特定项目IRS A2A submission,当我认为需要将前缀添加到
签名
元素时,我使用了它。然而,在与其他一些SO用户的讨论中,我放弃了在
签名
元素中添加前缀的想法,因为这实际上是不必要的。

为此,我们尝试了同样的方法,即无前缀传递签名,但仍然陷入.NET中的WS-security错误。您是否在.NET或任何引用中传递了此错误?