Using XmlSerializer for custom data serialization
When transferring custom data objects in a WCF service operation (as parameters or return values), the runtime will serialize the objects into XML elements, which are embedded in the underlying SOAP XML message. By default, WCF runtime uses the DataContractSerializer
for serializing the .NET objects into XML or binary content. And the DataContractSerializer
does have many advantages for DataContract
serialization as compared to the traditional XmlSerializer used in ASMX Web Service. However, sometimes we will prefer using the XmlSerializer for data object serialization in a WCF service. For example, when talking to some non-.NET platform, like a Java-based service or client, using XmlSerializer will help us to gain more control over the serialization/deserialization between a .NET object and XML content. This is to produce a compatible DataContract
between service and client more conveniently.
In this recipe, we will use a sample WCF service...