Showing posts with label Data Contract in WCF. Show all posts
Showing posts with label Data Contract in WCF. Show all posts

Friday, 15 March 2013

WCF Lesson 2:- Data Contract in WCF



for any query you can mail me at Malhotra.isha3388@gmail.com.
you can also mail me your wcf problem which you face in your project

Data Contract in WCF

In the previous article I described basic Idea of WCF and Service Contract. Now I am going to describe your data contract.
As we know that WCF exchange information in XML format. Data contract defines which data type is serialized (convert into Xml). Primitive data types like int, string etc. serialized already as they defined in XSD (Xml Schema Definition). But custom data types like classes are not.
Wcf uses serialization engine i.e. Data Contract Serializer by default to serialize and DE serialize the data.
We can use DataContract attribute to serialize the class and DataMember attribute to Serialize its member.

For Example:-

In following example I simply create a class EmpData and declare two members in it. In service I create a simple method which returns the object of EmpData with some information.