In WCF, if I have code like this and I'm returning it in XML format, the XML is auto generated. Is it possible for me to expicitly specify which XML will be used for the serialization of the CustomerEntity?
[OperationContract]
[WebInvoke(Method = "GET"]
CustomerEntity GetCustomer(int customerPk);
The alternative that I'm currently using is to return an XElement, but the problem with this is that I can't also support JSon that way.
Update: My types are immutable and use raedonly properties, so IXmlSerializable won't work for me.
Implement IXmlSerializable on CustomerEntity.
You can try using Raw messages i.e. using Contract types deriving from Message class and writing the messages the way you want by overriding OnWriteBodyContents and other overridable Message class members. Please refer "Inheriting from the Message Class" section gof following MSDN article to know more about overridable members of Message class, http://msdn.microsoft.com/en-us/library/ms734675.aspx
HTH, Amit