wcf return an XmlDocument?

Blaze picture Blaze · Jun 8, 2009 · Viewed 26.6k times · Source

I have a WCF service where Im building up a block of XML using an XmlWriter. Once complete I want to have the WCF return it as an XmlDocument.

But if I have XmlDocument in the [OperationContract] it doesnt work:

[OperationContract]
XmlDocument GetNextLetter();

The WCF test utility gives:

System.Runtime.Serialization.InvalidDataContractException: Type 'System.Xml.XmlDocument' cannot be serialized.

Answer

maelo picture maelo · Jun 4, 2012

append xmlserializer on what you did in the operational contract

[OperationContract,XmlSerializerFormat]
XmlDocument GetNextLetter();

this will do it !