tags:

views:

31

answers:

1

I'd like my WCF service to return an xml file that has been signed.

I found documentation that shows how to sign an XmlDocument on msdn, but since a WCF function can't return an XmlDocument I'm not sure if the following would work (similar to thisquestion)

public XmlElement GetXml() {
        var doc = new XmlDocument();
        // add data to doc
        // sign doc
        return doc.DocumentElement;
    }

Would it still be possible to verify the signature of doc.DocumentElement if I added it to another XmlDocument after a client requested it? Is there a better way to do this?

Thanks!

A: 

XmlDocument is not decorated with DataContractAttribute and I cannot see why the object needs to be sent over the wire while the serialized form (text form) is all that is required.

I would design it as:

[OperationContract]
string GetFooXml();

And send the string. That is what WCF/XML is for, sending data as text whenever possible so that more kinds of clients can consume it.

Aliostad
Do you mean sending XML as encoded string?
Ladislav Mrnka
Yes, pretty much. It will be escaped when it is sent so you shouldn't have any problem.
Aliostad