Monday, 26 January 2015

WCF DATA CONTRACT & DATA MEMBERS



WCF DATA CONTRACT & DATA MEMBERS

What is Serialization: is an process of converting an object into an XML representation. In WCF default serialization is Data Contract Serialization.
But we have another option also, which we know as SerializableAttribute.
In Data Contract Serialization, it will serialize all public properties in Alphabetic order and private fields and properties are excluding.

When we decorate a complex type with [Serializable] attribute the Data contract serialize all fields. With this keyword we don’t have explicit control on what filed to include and exclude in serialized data.
When we decorate a complex type with [Data Contract] attribute, this Data Contract serialize all the fields which marks as the [Data Member] attribute and which not marked with this keyword exclude from the serialization process.  It can also be applies on private fields.
In WCF the most way of serialization is to mark the type with [Data Contract] attributes and mark each member that needs to be serialized with the [Data Member].

Service Contract:
This name attribute give explicit name to prevent the client from breaking when service contract interface name change. It may possible during the development phase you change the name of the interface but also keep it in mind that the client never affects from these changes. In WCF we called Port type. You can think of this prototype as the Interface the clients use to communicate with WCF service. When you don’t set the name property on a service contract attribute, by default the name of the prototype XML element in WSDL will be the name of the service contract interface.

Is Multiple Service Contract?
Yes,
it is possible in WCF to implement multiple service contracts. We can make the service class implement multiple service interfaces and then expose each service using a different endpoint.

stats counter
your visitor number