I have a WCF rest service. It has a method that returns a list of objects. The object type is set as a DataContract and it has DataMembers. Now it works great, I can get my list of objects as an XML via my method. It is great and nice.
My question is: is there any way to get result XML before returning it from the method? So, can I have exactly the same XML in my method as I can get when calling my method via REST?
.net4/vs2010
Alfonso’s answer is somewhat right, but you mentioned you’re using
DataContractandDataMember. TheXmlSerializerclass is not meant to be used with data contracts. Instead what you’re looking for isDataContractSerializer. Use of that is very similar, but would look like this instead: