tags:

views:

27

answers:

3

By default WCF use DataContractSerialization so if we can change it then my question is how to change it and when should we need which serialization on wcf ?

+1  A: 

You can use the XmlSerializerFormatAttribute attribute on your service contract to force WCF to use the XmlSerializer.

Graham Clark
+1  A: 

The default choice of DataContractSerializer is good for most purpose. You can also use the DataContractJsonSerializer specially for REST type services and if the client expects Json content type. The other option is XmlSerializer for interoperability purpose if you need more control over the generated XML. DataContractSerializer is more efficient than XmlSerializer.

In 3rd party options you can use protobuf-net from Google which is more efficient than DataContract Serializer.

Pratik
+1  A: 

WCF has a nice feature that a method can return Message or a Stream (see Returning raw json (string) in wcf and How to set Json.Net as the default serializer for WCF REST service as examples). The corresponding code which you need to write can be more easy as if you will use more advance techniques Extending Encoders and Serializers. So it is very easy to implement Streaming Message Transfer for example or just returning JPG or Excel file as a result of some WCF method.

Oleg