9

I know there's 3 type s of serialization in .net :

Soap , Xml , Binary.

Wcf instructed the DataContract attribute which also serialize ... but via what ?

Binary is not - i know.

So by which mechanism ?

Royi Namir
  • 144,742
  • 138
  • 468
  • 792

2 Answers2

16

It is the binding defined for the given endpoint which specifies the serialization mechanism. For example:

  • basicHttpBinding and wsHttpBinding use SOAP
  • netTcpBinding uses binary serialization
  • webHttpBinding could use XML, Json, ...

You can read more about the different built-in bindings and their properties on this article. Thanks to the extensibility of WCF you could of course write your own custom bindings.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
15

You are messing two techniques together.

  • Serialization - how objects are converted to messages - we have XML and JSON formatters available out of the box (DataContractSerializer, DataContractJsonSerializer, XmlSerializer)
  • Encoding - how the message is transferred - we have three encoders out of the box
    • TextMessageEncoder - for SOAP messages transferred as text - also supports MTOM and POX (Plain old XML) if message version is set to None
    • BinaryMessageEncoder - for XML/SOAP messages transferred as binary data
    • WebMessageEncoder - for XML and JSON messages in REST services

These features are used by standard bindings. WCF support as many serializations and encoding as you want => you can build your own.

Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670