WCF Service Return erroneous XML

0

I created a Post WCF service in C # that signs an xml document, all right, but when I invoke my service from the postman client, it returns me with special and incorrect characters.

This is my services:

IService1: 

[ServiceContract]
    public interface IService1
    {
        [OperationContract()]
        [WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Xml, RequestFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "/GetFirmaXML")]
        string GetFirmaXML(string appid, string xml);
    }

This is the service.cs part:

string IService1.GetFirmaXML(string pCertificado, string xml)
        {
            return FirmarDocumentoXml(pCertificado, xml).InnerXml;
        }

public static XmlDocument FirmarDocumentoXml(string cCertificado, string archivoXml)
        {
            var xmlDoc = new XmlDocument { PreserveWhitespace = true };
            xmlDoc.LoadXml(archivoXml);

        XmlDeclaration xmlDeclaracion;
        xmlDeclaracion = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", "yes");

        var cert = GetSignerCert(cCertificado); // Extraer certificado

        String idReference = "ID";

        if (xmlDoc == null)
            throw new ArgumentException("xmlDoc");
        if (cert == null)
            throw new ArgumentException("Key");

        SignedXml signedXml = new SignedXml(xmlDoc);
        signedXml.SigningKey = cert.PrivateKey;

        Reference reference = new Reference();
        reference.Uri = "";

        XmlDsigEnvelopedSignatureTransform env = new XmlDsigEnvelopedSignatureTransform();
        reference.AddTransform(env);
        signedXml.AddReference(reference);

        var keyInfo = new System.Security.Cryptography.Xml.KeyInfo();
        var x509Chain = new X509Chain();
        x509Chain.Build(cert);
        var objChainElements = x509Chain.ChainElements[0];
        var x509Data = new KeyInfoX509Data(objChainElements.Certificate, X509IncludeOption.EndCertOnly); // Verificar 20 segundos

        keyInfo.AddClause(x509Data);
        signedXml.KeyInfo = keyInfo;

        signedXml.ComputeSignature();

        XmlElement xmlDigitalSignature = signedXml.GetXml();
        xmlDigitalSignature.Prefix = "ds";


        xmlDigitalSignature.SetAttribute("Id", idReference);

        XmlNode proposito = xmlDoc.CreateNode("element", "Proposito", "");
        proposito.InnerText = "Cumple proposito";
        xmlDigitalSignature.AppendChild(proposito);

        XmlNode revocacion = xmlDoc.CreateNode("element", "Revocacion", "");
        revocacion.InnerText = "Cumple revocacion";
        xmlDigitalSignature.AppendChild(revocacion);

        XmlNode tls = xmlDoc.CreateNode("element", "TLS", "");
        tls.InnerText = "Cumple TLS";
        xmlDigitalSignature.AppendChild(tls);

        XmlNode expiracion = xmlDoc.CreateNode("element", "Expiracion", "");
        expiracion.InnerText = "Cumple expiracion";
        xmlDigitalSignature.AppendChild(expiracion);

        xmlDoc.DocumentElement.AppendChild(xmlDoc.ImportNode(xmlDigitalSignature, true));

        var nsMgr = new XmlNamespaceManager(xmlDoc.NameTable);

        var digestValue = reference.DigestValue;
        nsMgr.AddNamespace("ext", "urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2");
        return xmlDoc;
    }

AND THIS IS THE POSTMAN CUSTOMER RESPONSE:

ANY IDEA OF HOW CAN I DO? THANK YOU

    
asked by Jvega10 08.09.2018 в 01:32
source

0 answers